private void GetBoundingBox()
        {
            Matrix4 mat = new Matrix4();

            mat.Identity();
            BoundingBoxUtils.GetBoundingBoxInLocal(this.Curves.ToArray(), null, mat, ref centerPt, ref disPt);
        }
        /// <summary>
        /// 获取电极头在Work坐标系下得外形点
        /// </summary>
        protected void GetHeadBounbingBox()
        {
            Matrix4 workInv = workMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMatr, workInv);

            BoundingBoxUtils.GetBoundingBoxInLocal(eleHead.ToArray(), csys, workMatr, ref centerPt, ref disPt);
        }
        /// <summary>
        /// 给齿上颜色
        /// </summary>
        private void SetHeadColour()
        {
            Matrix4 matr = new Matrix4();

            matr.Identity();
            Matrix4 inv = matr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(matr, inv);
            List <Body> bodys     = Session.GetSession().Parts.Work.Bodies.ToArray().ToList();
            var         toolhList = bodys.GroupBy(a => AttributeUtils.GetAttrForString(a, "ToolhName"));
            List <ElectrodeToolhInfo[, ]> toolhInfos = new List <ElectrodeToolhInfo[, ]>();

            try
            {
                foreach (var toolh in toolhList)
                {
                    ElectrodeToolhInfo[,] toolhInfo = pitch.GetToolhInfosForAttribute(toolh.ToList(), matr, csys);
                    toolhInfos.Add(toolhInfo);
                }
                if (toolhInfos.Count != 0)
                {
                    gapValue.SetERToolh(toolhInfos);
                }
            }
            catch (Exception ex)
            {
                ClassItem.WriteLogFile("设置颜色错误!" + ex.Message);
            }
        }
        public void ExpandToSquare_BoundingBoxERight_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(-80.0f, -0.0f, 10.0f, 90.0f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxE, RelativePosition.Right);

            CompareBoundingBoxes(expected, actual);
        }
Example #5
0
 public override void SetMaterial(Material material)
 {
     foreach (var handle in handles)
     {
         BoundingBoxUtils.ApplyMaterialToAllRenderers(handle.visual, material);
     }
 }
        public void ExpandToSquare_BoundingBoxABottomRight_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(6.9f, 3.1f, 42.0f, 38.2f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxA, RelativePosition.BottomRight);

            CompareBoundingBoxes(expected, actual);
        }
        public void ExpandToSquare_BoundingBoxBCenter_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(-12.3f, -68.4f, 78.9f, 22.8f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxB, RelativePosition.Center);

            CompareBoundingBoxes(expected, actual);
        }
        public void ExpandToSquare_BoundingBoxATopLeft_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(6.9f, -10.1f, 42.0f, 25.0f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxA, RelativePosition.TopLeft);

            CompareBoundingBoxes(expected, actual);
        }
        public void ExpandToSquare_BoundingBoxACenter_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(6.9f, -3.5f, 42.0f, 31.6f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxA, RelativePosition.Center);

            CompareBoundingBoxes(expected, actual);
        }
        public void ExpandToSquare_BoundingBoxB_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(-12.3f, -90.0f, 78.9f, 1.2f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxB);

            CompareBoundingBoxes(expected, actual);
        }
        public void ExpandToSquare_BoundingBoxBBottom_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(-12.3f, -45.6f, 78.9f, 45.6f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxB, RelativePosition.Bottom);

            CompareBoundingBoxes(expected, actual);
        }
        public void ExpandToSquare_BoundingBoxFBottom_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(-135.0f, -30.0f, 135.0f, 60.0f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxF, RelativePosition.Bottom);

            CompareBoundingBoxes(expected, actual);
        }
        /// <summary>
        /// 移动
        /// </summary>
        /// <param name="vec"></param>
        /// <returns></returns>
        public bool MovePositionBuilder(Vector3d vec)
        {
            try
            {
                Matrix4 inv = this.work.Info.Matr.GetInversMatrix();
                CartesianCoordinateSystem csys        = BoundingBoxUtils.CreateCoordinateSystem(this.work.Info.Matr, inv);
                ElectrodeSetValueInfo     setValue    = ElectrodeSetValueInfo.GetAttribute(eleComp);
                ElectrodeSetValueInfo     newSetValue = setValue.Clone() as ElectrodeSetValueInfo;

                AssmbliesUtils.MoveCompPart(eleComp, vec, work.Info.Matr);
                NXObject instance = AssmbliesUtils.GetOccOfInstance(eleComp.Tag);
                BodyInfo info     = GetDischargeFace(csys, eleComp);
                newSetValue.EleSetValue[0]    = setValue.EleSetValue[0] + vec.X;
                newSetValue.EleSetValue[1]    = setValue.EleSetValue[1] + vec.Y;
                newSetValue.EleSetValue[2]    = setValue.EleSetValue[2] + vec.Z;
                newSetValue.Positioning       = GetPositionName();
                newSetValue.PositioningRemark = "设定值改变";
                if (info != null)
                {
                    newSetValue.ContactArea   = info.ContactArea;
                    newSetValue.ProjectedArea = info.GetProjectedArea(csys, this.work.Info.Matr);
                }
                newSetValue.SetAttribute(instance);
                return(true);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("电极跑位错误!" + ex.Message);
                return(false);
            }
        }
        public void ParseBoundingBox_BoundingBoxBReversed_ParsesCorrectly()
        {
            string      boundingBoxString = "78.9,0,-12.3,-45.6";
            BoundingBox boundingBox       = BoundingBoxUtils.ParseBoundingBox(boundingBoxString);

            Assert.AreEqual(_boundingBoxB, boundingBox);
        }
        public void ParseBoundingBox_BoundingBoxCLongWrapped_ParsesCorrectly()
        {
            string      boundingBoxString = "315,0,45,90";
            BoundingBox boundingBox       = BoundingBoxUtils.ParseBoundingBox(boundingBoxString);

            Assert.AreEqual(_boundingBoxC, boundingBox);
        }
        public void CalculateUVBounds_BoundingBoxCE_CorrectResults()
        {
            UVBounds expected = new UVBounds(5 / 18f, 0f, 11 / 18f, 1f);
            UVBounds actual   = BoundingBoxUtils.CalculateUVBounds(_boundingBoxC, _boundingBoxE);

            Assert.AreEqual(expected, actual);
        }
        public void ParseBoundingBox_BoundingBoxAReversed_ParsesCorrectly()
        {
            string      boundingBoxString = "42.00,25.00,6.90,3.10";
            BoundingBox boundingBox       = BoundingBoxUtils.ParseBoundingBox(boundingBoxString);

            Assert.AreEqual(_boundingBoxA, boundingBox);
        }
Example #18
0
        private void GetBoundingBox()
        {
            Point3d     centerPt = new Point3d();
            Point3d     disPt    = new Point3d();
            Part        workPart = Session.GetSession().Parts.Work;
            List <Body> bodys    = new List <Body>();

            //  NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, part)[0];
            foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(workPart, part))
            {
                if (!ct.IsSuppressed)
                {
                    foreach (Body body in this.part.Bodies.ToArray())
                    {
                        bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, body.Tag) as Body);
                    }
                }
            }
            Matrix4 invers = workMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMatr, invers);//坐标

            BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, workMatr, ref centerPt, ref disPt);
            LayerUtils.MoveDisplayableObject(201, bodys.ToArray());
            this.CenterPt = centerPt;
            this.DisPt    = disPt;
        }
        public void ExpandToSquare_BoundingBoxFCenter_CorrectResults()
        {
            BoundingBox expected = new BoundingBox(-135.0f, -45.0f, 135.0f, 45.0f);
            BoundingBox actual   = BoundingBoxUtils.ExpandToSquare(_boundingBoxF, RelativePosition.Center);

            CompareBoundingBoxes(expected, actual);
        }
Example #20
0
        /// <summary>
        /// 创建外形点
        /// </summary>
        /// <returns></returns>
        private Point[] CreateMinAndMaxPt()
        {
            UFSession theUFSession = UFSession.GetUFSession();

            Point[] pt       = new Point[2];
            Point3d centerPt = new Point3d();
            Point3d disPt    = new Point3d();

            List <Body> bodys = new List <Body>();

            foreach (Body body in this.workpiece.Bodies.ToArray())
            {
                bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(this.workpieceComp.Tag, body.Tag) as Body);
            }
            //  Body[] bodys = this.workpiece.Bodies.ToArray();
            Matrix4 invers = this.work.WorkMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(this.work.WorkMatr, invers);//坐标

            BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, this.work.WorkMatr, ref centerPt, ref disPt);
            this.CenterPt = centerPt;
            this.DisPt    = disPt;
            Point3d minPt = new Point3d(centerPt.X - disPt.X, centerPt.Y - disPt.Y, centerPt.Z - disPt.Z);
            Point3d maxPt = new Point3d(centerPt.X + disPt.X, centerPt.Y + disPt.Y, centerPt.Z + disPt.Z);

            invers.ApplyPos(ref maxPt);
            invers.ApplyPos(ref minPt);
            // PartUtils.SetPartWork(workpieceComp);
            pt[0] = PointUtils.CreatePoint(minPt);
            theUFSession.Obj.SetLayer(pt[0].Tag, 254);
            pt[1] = PointUtils.CreatePoint(maxPt);
            theUFSession.Obj.SetLayer(pt[1].Tag, 254);
            // PartUtils.SetPartWork(null);
            return(pt);
        }
        public void MedianLatLon_BoundingBoxD_CorrectResult()
        {
            Vector2 expected = new Vector2(-45.0f, -45.0f);
            Vector2 actual   = BoundingBoxUtils.MedianLatLon(_boundingBoxD);

            Assert.AreEqual(expected, actual);
        }
        public void CalculateUVBounds_BoundingBoxEC_CorrectResults()
        {
            UVBounds expected = new UVBounds(-5 / 6f, 0f, 13 / 6f, 1f);
            UVBounds actual   = BoundingBoxUtils.CalculateUVBounds(_boundingBoxE, _boundingBoxC);

            Assert.AreEqual(expected, actual);
        }
        public void CalculateUVBounds_BoundingBoxFSameSize2_CorrectResults()
        {
            BoundingBox selectedArea = new BoundingBox(120.0f, 0.0f, -150.0f, 60.0f);
            UVBounds    expected     = new UVBounds(-1 / 6f, -1 / 2f, 5 / 6f, 1 / 2f);
            UVBounds    actual       = BoundingBoxUtils.CalculateUVBounds(_boundingBoxF, selectedArea);

            Assert.AreEqual(expected, actual);
        }
        public void CalculateUVBounds_BoundingBoxCSameAspect_CorrectResults()
        {
            BoundingBox selectedArea = new BoundingBox(-30.0f, 0.0f, 15.0f, 45.0f);
            UVBounds    expected     = new UVBounds(1 / 6f, 1 / 2f, 2 / 3f, 1f);
            UVBounds    actual       = BoundingBoxUtils.CalculateUVBounds(_boundingBoxC, selectedArea);

            Assert.AreEqual(expected, actual);
        }
        public void CalculateUVBounds_BoundingBoxCSameSize_CorrectResults()
        {
            BoundingBox selectedArea = new BoundingBox(-15.0f, -30.0f, 75.0f, 60.0f);
            UVBounds    expected     = new UVBounds(1 / 3f, 1 / 3f, 4 / 3f, 4 / 3f);
            UVBounds    actual       = BoundingBoxUtils.CalculateUVBounds(_boundingBoxC, selectedArea);

            Assert.AreEqual(expected, actual);
        }
        public void CalculateUVBounds_BoundingBoxFSameSize1_CorrectResults()
        {
            new BoundingBox(-135.0f, -30.0f, 135.0f, 30.0f);
            BoundingBox selectedArea = new BoundingBox(90.0f, -30.0f, 180.0f, 30.0f);
            UVBounds    expected     = new UVBounds(-1 / 2f, 0f, 1 / 2f, 1f);
            UVBounds    actual       = BoundingBoxUtils.CalculateUVBounds(_boundingBoxF, selectedArea);

            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// 获取工件在Work坐标系下得外形点
        /// </summary>
        protected void GetWorkpieceBounbingBox(Part workpiecePart, out Point3d workpieceCenterPt, out Point3d workpieceDisPt)
        {
            workpieceDisPt    = new Point3d();
            workpieceCenterPt = new Point3d();
            Matrix4 workInv = workMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMatr, workInv);

            BoundingBoxUtils.GetBoundingBoxInLocal(workpiecePart.Bodies.ToArray(), csys, workMatr, ref workpieceCenterPt, ref workpieceDisPt);
        }
 public void ExpandToSquare_BoundingBoxC_CorrectResults()
 {
     // All Positions should return the original bounding box for this test case.
     foreach (RelativePosition position in Enum.GetValues(typeof(RelativePosition)))
     {
         BoundingBox result = BoundingBoxUtils.ExpandToSquare(_boundingBoxC, position);
         CompareBoundingBoxes(result, _boundingBoxC);
     }
 }
        public void MedianDirection_BoundingBoxD_CorrectResult()
        {
            Vector3 expected = new Vector3(0.5f, -Mathf.Sqrt(0.5f), 0.5f);
            Vector3 actual   = BoundingBoxUtils.MedianDirection(_boundingBoxD);

            for (int i = 0; i < 3; i++)
            {
                TestUtils.CompareFloats(expected[i], actual[i], _floatCompareDecimalPrecision);
            }
        }
        public void MedianLatLon_BoundingBoxB_CorrectResult()
        {
            Vector2 expected = new Vector2(-22.8f, 33.3f);
            Vector2 actual   = BoundingBoxUtils.MedianLatLon(_boundingBoxB);

            for (int i = 0; i < 2; i++)
            {
                TestUtils.CompareFloats(expected[i], actual[i], _floatCompareDecimalPrecision);
            }
        }