Exemple #1
0
        /// <summary>
        /// 获取加工方向
        /// </summary>
        public static string GetDIRECTION(Snap.Vector topFaceDir)
        {
            var temptopFaceDir = topFaceDir;
            var tempAixValue   = "Z+";

            if (SnapEx.Helper.Equals(temptopFaceDir, -Snap.Globals.WcsOrientation.AxisZ, SnapEx.Helper.Tolerance))
            {
                tempAixValue = "Z-";
            }
            if (SnapEx.Helper.Equals(temptopFaceDir, Snap.Globals.WcsOrientation.AxisX, SnapEx.Helper.Tolerance))
            {
                tempAixValue = "X+";
            }
            if (SnapEx.Helper.Equals(temptopFaceDir, -Snap.Globals.WcsOrientation.AxisX, SnapEx.Helper.Tolerance))
            {
                tempAixValue = "X-";
            }
            if (SnapEx.Helper.Equals(temptopFaceDir, Snap.Globals.WcsOrientation.AxisY, SnapEx.Helper.Tolerance))
            {
                tempAixValue = "Y+";
            }
            if (SnapEx.Helper.Equals(temptopFaceDir, -Snap.Globals.WcsOrientation.AxisY, SnapEx.Helper.Tolerance))
            {
                tempAixValue = "Y-";
            }

            return(tempAixValue);
        }
Exemple #2
0
        public static Snap.Position?GetElecMidPosition(Snap.NX.Part workPart, Snap.NX.Body body)
        {
            Snap.Position?result = null;
            var           point  = GetElecMidPointInPart(workPart, body);

            if (point == null)
            {
                var name = GetStringAttribute(body, SnapEx.EactConstString.EACT_ELECT_GROUP);
                if (!string.IsNullOrEmpty(name))
                {
                    if (body.NXOpenBody.OwningComponent != null && body.OwningComponent.Prototype != null)
                    {
                        var           part     = body.OwningComponent.Prototype;
                        Snap.NX.Point oldPoint = GetElecMidPointInPart(part, body);
                        if (oldPoint != null)
                        {
                            var           oldPosition = new Snap.Position(oldPoint.X, oldPoint.Y, oldPoint.Z);
                            var           vCom        = Snap.Vector.Unit(body.OwningComponent.Orientation.AxisZ);
                            var           v2          = new Snap.Vector(oldPosition);
                            Snap.Position newPosition = body.OwningComponent.Position - (vCom + v2);
                            result = newPosition;
                        }
                    }
                }
            }
            else
            {
                result = point.Position;
            }

            return(result);
        }
Exemple #3
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            try
            {
                var theSession = NXOpen.Session.GetSession();
                var workPart   = theSession.Parts.Work;
                var infos      = gridControl1.DataSource as List <JYElecInfo>;
                if (infos != null)
                {
                    infos.ForEach(u =>
                    {
                        string path       = Path.Combine(Path.GetDirectoryName(workPart.FullPath), string.Format("{0}{1}", u.ElecName, Path.GetExtension(workPart.FullPath)));
                        var firstPosition = u.PositioningInfos.FirstOrDefault();
                        var lines         = firstPosition.Lines;
                        var basePoint     = (lines.First() + lines.Last()) / 2;

                        var trans      = Snap.Geom.Transform.CreateTranslation(new Snap.Position() - basePoint);
                        Snap.Vector v1 = new Snap.Vector(0, 0, 1);
                        var faceDir    = firstPosition.FaceDir;
                        var angle      = Snap.Vector.Angle(v1, faceDir);
                        var trans1     = Snap.Geom.Transform.CreateRotation(new Snap.Position(), new Snap.Orientation(faceDir).AxisY, angle);
                        trans          = Snap.Geom.Transform.Composition(trans, trans1);
                        var c          = SnapEx.Create.ExtractObject(firstPosition.NXObjects, path, true, true, trans, basePoint, new Snap.Orientation(faceDir));

                        u.PositioningInfos.ForEach(m =>
                        {
                            m.NXObjects.ForEach(n =>
                            {
                                Snap.NX.NXObject snapN = n;
                                snapN.Delete();
                            });

                            if (m != firstPosition && c != null)
                            {
                                var mLines                     = m.Lines;
                                var mBasePoint                 = (mLines.First() + mLines.Last()) / 2;
                                Snap.NX.Component snapC        = c;
                                Snap.NX.Component newComponent = workPart.ComponentAssembly.CopyComponents(new List <NXOpen.Assemblies.Component> {
                                    c
                                }.ToArray()).First();

                                var transForm = Snap.Geom.Transform.CreateTranslation(mBasePoint - snapC.Position);
                                //平移旋转
                                var tempTrans           = transForm.Matrix;
                                NXOpen.Matrix3x3 matrix = new NXOpen.Matrix3x3();
                                matrix.Xx = tempTrans[0]; matrix.Xy = tempTrans[4]; matrix.Xz = tempTrans[8];
                                matrix.Yx = tempTrans[1]; matrix.Yy = tempTrans[5]; matrix.Yz = tempTrans[9];
                                matrix.Zx = tempTrans[2]; matrix.Zy = tempTrans[6]; matrix.Zz = tempTrans[10];
                                workPart.ComponentAssembly.MoveComponent(newComponent, new NXOpen.Vector3d(tempTrans[3], tempTrans[7], tempTrans[11]), matrix);
                            }
                        });
                    });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #4
0
 static bool _Equals(Snap.Vector v1, Snap.Vector v2, double tolerance)
 {
     v1 = Snap.Vector.Unit(v1);
     v2 = Snap.Vector.Unit(v2);
     if (Math.Abs((v1.X - v2.X)) < tolerance && Math.Abs((v1.Y - v2.Y)) < tolerance && Math.Abs((v1.Z - v2.Z)) < tolerance)
     {
         return(true);
     }
     return(false);
 }
Exemple #5
0
        public static Snap.Geom.Transform GetElecTransWcsToAcs(Snap.Vector baseDir, Snap.Orientation wcs)
        {
            var wcsOrientation      = GetStandardOrientation(wcs);
            var acsOrientation      = Snap.Orientation.Identity;
            var transR              = Snap.Geom.Transform.CreateRotation(acsOrientation, wcsOrientation);
            var baseFaceOrientation = new Snap.Orientation(-baseDir.Copy(transR));

            baseFaceOrientation = GetSidelongOrientation(baseFaceOrientation);
            transR = Snap.Geom.Transform.Composition(transR, Snap.Geom.Transform.CreateRotation(acsOrientation, baseFaceOrientation));
            return(transR);
        }
Exemple #6
0
        public List <AB> GetABList(Snap.Position p, Snap.Vector pV)
        {
            var list = GetABList();

            list = Business.OrderProbeDataAB(list, p, pV);
            var tempList = list.Where(u => u.A == 0 && u.B == 0).ToList();

            tempList.ForEach(u => {
                list.Remove(u);
            });
            tempList.ForEach(u => {
                list.Insert(0, u);
            });
            return(list);
        }
Exemple #7
0
        /// <summary>
        /// 获取摄像机视角
        /// </summary>
        public static Snap.Orientation GetCameraOrientation(Snap.Orientation ori, Electrode elec = null)
        {
            var wcsOrientation = Electrode.GetStandardOrientation(Snap.Globals.WcsOrientation);
            var acsOrientation = Snap.Orientation.Identity;
            var transR         = Snap.Geom.Transform.CreateRotation(acsOrientation, wcsOrientation);

            var X = new Snap.Vector(ori.AxisX.X, ori.AxisX.Y, ori.AxisX.Z).Copy(transR);
            var Y = new Snap.Vector(ori.AxisY.X, ori.AxisY.Y, ori.AxisY.Z).Copy(transR);

            if (elec != null)
            {
                var baseDirOrientation = Electrode.GetSidelongOrientation(new Snap.Orientation(-elec.BaseFace.GetFaceDirection()));
                var transR1            = Snap.Geom.Transform.CreateRotation(baseDirOrientation, wcsOrientation);
                X = X.Copy(transR1);
                Y = Y.Copy(transR1);
            }

            return(new Snap.Orientation(X, Y));
        }
Exemple #8
0
        public static Snap.NX.Point GetElecMidPoint(Snap.NX.Part workPart, Snap.NX.Body body)
        {
            var point = GetElecMidPointInPart(workPart, body);

            if (point == null)
            {
                var name = GetStringAttribute(body, SnapEx.EactConstString.EACT_ELECT_GROUP);
                if (!string.IsNullOrEmpty(name))
                {
                    if (body.NXOpenBody.OwningComponent != null && body.OwningComponent.Prototype != null)
                    {
                        var           part     = body.OwningComponent.Prototype;
                        Snap.NX.Point oldPoint = GetElecMidPointInPart(part, body);
                        if (oldPoint != null)
                        {
                            SnapEx.Create.ExtractObject(new List <NXOpen.NXObject> {
                                oldPoint
                            }, workPart.FullPath, false, false);
                            oldPoint = GetElecMidPointInPart(workPart, body);
                            if (oldPoint != null)
                            {
                                var           oldPosition = new Snap.Position(oldPoint.X, oldPoint.Y, oldPoint.Z);
                                var           vCom        = Snap.Vector.Unit(body.OwningComponent.Orientation.AxisZ);
                                var           v2          = new Snap.Vector(oldPosition);
                                Snap.Position newPosition = body.OwningComponent.Position - (vCom + v2);
                                oldPoint.X = newPosition.X;
                                oldPoint.Y = newPosition.Y;
                                oldPoint.Z = newPosition.Z;
                                point      = oldPoint;
                            }
                        }
                    }
                }
            }
            else
            {
                point = point.Copy();
            }

            return(point);
        }
Exemple #9
0
        /// <summary>
        /// 获取基准角法向
        /// </summary>
        public static Snap.Vector GetBaseCornerDirection(Snap.Vector director, Snap.NX.Body body, Snap.Position basePoint)
        {
            var vec = new Snap.Vector();

            director = director.Copy(Snap.Geom.Transform.CreateRotation(basePoint, 90));

            Snap.NX.Face baseFace = null;

            var faces = body.Faces.ToList();

            faces.ForEach(u =>
            {
                var box = u.BoxUV;
                var p1  = u.Position((box.MinU + box.MaxU) / 2, (box.MaxV + box.MinV) / 2);
                if (SnapEx.Helper.Equals(p1, basePoint, _tolerance))
                {
                    baseFace = u;
                    return;
                }
            });

            if (baseFace != null)
            {
                faces.Remove(baseFace);
                faces.ForEach(u =>
                {
                    if (u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane &&
                        u.Box.MaxZ > basePoint.Z &&
                        SnapEx.Helper.Equals(u.GetFaceDirection(), director) &&
                        SnapEx.Helper.Equals(u.GetFaceDirection(), -director)
                        )
                    {
                        u.Color = System.Drawing.Color.Red;
                    }
                });
            }

            return(vec);
        }
Exemple #10
0
        /// <summary>
        /// 获取侧放矩阵
        /// </summary>
        public static Snap.Orientation GetSidelongOrientation(Snap.Orientation baseDirOrientation)
        {
            var or       = GetStandardOrientation(baseDirOrientation);
            var identity = Snap.Orientation.Identity;

            Snap.Vector x = or.AxisX;
            Snap.Vector y = or.AxisY;
            if (SnapEx.Helper.Equals(or.AxisZ, -identity.AxisY))
            {
                x = identity.AxisX;
                y = identity.AxisZ;
            }
            else if (SnapEx.Helper.Equals(or.AxisZ, identity.AxisY))
            {
                x = -identity.AxisX;
                y = identity.AxisZ;
            }
            else if (SnapEx.Helper.Equals(or.AxisZ, -identity.AxisX))
            {
                x = -identity.AxisY;
                y = identity.AxisZ;
            }
            else if (SnapEx.Helper.Equals(or.AxisZ, identity.AxisX))
            {
                x = identity.AxisY;
                y = identity.AxisZ;
            }
            else if (SnapEx.Helper.Equals(or.AxisZ, -identity.AxisZ))
            {
                x = identity.AxisX;
                y = -identity.AxisY;
            }
            else
            {
                return(or);
            }
            return(new Snap.Orientation(x, y));
        }
Exemple #11
0
        /// <summary>
        /// 获取象限类型
        /// </summary>
        public static QuadrantType GetQuadrantType(Snap.Vector vector)
        {
            QuadrantType type = QuadrantType.First;
            var          x    = vector.X;
            var          y    = vector.Y;

            if (x > 0 && y > 0)        //第一象限
            {
                type = QuadrantType.First;
            }
            else if (x < 0 && y > 0)       //第二象限
            {
                type = QuadrantType.Second;
            }
            else if (x < 0 && y < 0)       //第三象限
            {
                type = QuadrantType.Three;
            }
            else                //第四象限
            {
                type = QuadrantType.Four;
            }
            return(type);
        }
Exemple #12
0
 public static bool Equals(Snap.Vector v1, Snap.Vector v2, double tolerance = Tolerance)
 {
     return(_Equals(v1, v2, tolerance));
 }
Exemple #13
0
        /// <summary>
        /// 自动编程
        /// </summary>
        public static void AutoCam(CAMElectrode ele, CNCConfig.CAMConfig camConfig)
        {
            //安全距离
            var safeDistance    = 10;
            var autoBlankOffset = new double[] { camConfig.AutoBlankXPlus, camConfig.AutoBlankXReduce, camConfig.AutoBlankYPlus, camConfig.AutoBlankYReduce, camConfig.AutoBlankZPlus, camConfig.AutoBlankZReduce };
            var eleInfo         = ele.Electrode.GetElectrodeInfo();
            var bodyBox         = ele.BodyBox;

            //几何组根节点
            NXOpen.Tag geometryGroupRootTag;
            //程序组根节点
            NXOpen.Tag orderGroupRootTag;
            //刀具组根节点
            NXOpen.Tag cutterGroupRootTag;
            //方法组根节点
            NXOpen.Tag methodGroupRootTag;
            //几何体组
            NXOpen.Tag workGeometryGroupTag;


            //TODO 初始化对象
            NXOpen.Tag setup_tag;
            ufSession.Setup.AskSetup(out setup_tag);
            ufSession.Setup.AskGeomRoot(setup_tag, out geometryGroupRootTag);
            ufSession.Setup.AskProgramRoot(setup_tag, out orderGroupRootTag);
            ufSession.Setup.AskMctRoot(setup_tag, out cutterGroupRootTag);
            ufSession.Setup.AskMthdRoot(setup_tag, out methodGroupRootTag);

            //根据配置文件创建刀具
            CNCConfig.CAMConfig.ProjectInfo projectConfig;
            var cutters = CreateCutter(ele, camConfig, cutterGroupRootTag, out projectConfig);

            //TODO删除旧的程序

            //TODO 创建坐标系和几何体
            //加工坐标系
            NXOpen.Tag workMcsGroupTag;
            ufSession.Ncgeom.Create(AUTOCAM_TYPE.mill_planar, AUTOCAM_SUBTYPE.MCS, out workMcsGroupTag);
            ufSession.Obj.SetName(workMcsGroupTag, AUTOCAM_ROOTNAME.GEOM_EACT);
            ufSession.Ncgroup.AcceptMember(geometryGroupRootTag, workMcsGroupTag);

            //TODO 设置安全平面
            var normal = new Snap.Vector(0, 0, 1);
            var origin = new Snap.Position((bodyBox.MinX + bodyBox.MaxX) / 2, (bodyBox.MinY + bodyBox.MaxY) / 2, bodyBox.MaxZ + safeDistance);

            ufSession.Cam.SetClearPlaneData(workMcsGroupTag, origin.Array, normal.Array);

            //TODO 创建几何体
            ufSession.Ncgeom.Create(AUTOCAM_TYPE.mill_planar, AUTOCAM_SUBTYPE.WORKPIECE, out workGeometryGroupTag);
            ufSession.Obj.SetName(workGeometryGroupTag, eleInfo.Elec_Name);
            ufSession.Ncgroup.AcceptMember(workMcsGroupTag, workGeometryGroupTag);

            //TODO 添加Body作为工作几何体
            Helper.SetCamgeom(NXOpen.UF.CamGeomType.CamPart, workGeometryGroupTag, new List <NXOpen.Tag> {
                ele.Electrode.ElecBody.NXOpenTag
            });

            //TODO 设置毛坯为自动块
            ufSession.Cam.SetAutoBlank(workGeometryGroupTag, NXOpen.UF.UFCam.BlankGeomType.AutoBlockType, autoBlankOffset);

            Action <string, double, int> action = (type, fireNum, number) => {
                //TODO 创建程序
                NXOpen.Tag programGroupTag;
                ufSession.Ncprog.Create(AUTOCAM_TYPE.mill_planar, AUTOCAM_SUBTYPE.PROGRAM, out programGroupTag);
                ufSession.Obj.SetName(programGroupTag, string.Format("{0}-{1}", eleInfo.Elec_Name, type));
                ufSession.Ncgroup.AcceptMember(orderGroupRootTag, programGroupTag);

                var list = CAMOper.CreateCamOper(workGeometryGroupTag, programGroupTag, methodGroupRootTag, cutterGroupRootTag, ele, projectConfig, cutters, fireNum);
                list = list.Where(u => u.OperIsValid).ToList();
                //var exMsg=Helper.PathGenerate(programGroupTag);
                //Helper.ShowInfoWindow(exMsg);
            };

            if (eleInfo.FINISH_NUMBER > 0)  //精
            {
                action("F", eleInfo.FINISH_SPACE, eleInfo.FINISH_NUMBER);
            }

            if (eleInfo.MIDDLE_NUMBER > 0)  //中
            {
                action("M", eleInfo.MIDDLE_SPACE, eleInfo.MIDDLE_NUMBER);
            }

            if (eleInfo.ROUGH_NUMBER > 0)  //粗
            {
                action("R", eleInfo.ROUGH_SPACE, eleInfo.ROUGH_NUMBER);
            }
        }
Exemple #14
0
 public static Snap.Geom.Transform GetElecTransWcsToAcs(Snap.Vector baseDir)
 {
     return(GetElecTransWcsToAcs(baseDir, Snap.Globals.WcsOrientation));
 }
Exemple #15
0
        public static void GetEactElectrode(Snap.NX.Body body, ref Snap.NX.Face topFace, ref Snap.NX.Face baseFace, ref Snap.NX.Point basePoint, ref Snap.Position pos)
        {
            var faces  = body.Faces.ToList();
            var topDir = new Snap.Vector(0, 0, 1);

            //顶面
            topFace = faces.Where(u => u.IsHasAttr(EactElectrode.BASE_BOT) || u.MatchAttrValue(XKElectrode.ATTR_NAME_MARK, XKElectrode.BASE_BOT)).FirstOrDefault();
            if (topFace == null)
            {
                var topFaces = faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane).Where(u => SnapEx.Helper.Equals(topDir, u.GetFaceDirection()));
                topFace = topFaces.FirstOrDefault();
                if (topFaces.Count() > 1)
                {
                    topFace = topFaces.OrderByDescending(u => {
                        var uv = u.BoxUV;
                        return(Math.Abs(uv.MinU - uv.MaxU) * Math.Abs(uv.MaxV - uv.MinV));
                    }).FirstOrDefault();
                }
            }
            //基准面
            baseFace = faces.Where(u => u.IsHasAttr(EactElectrode.BASE_TOP) || u.MatchAttrValue(XKElectrode.ATTR_NAME_MARK, XKElectrode.BASE_TOP)).FirstOrDefault();
            if (baseFace == null)
            {
                var baseFaces = faces.Where(u => u.ObjectSubType == Snap.NX.ObjectTypes.SubType.FacePlane).Where(u => SnapEx.Helper.Equals(-topDir, u.GetFaceDirection()));
                if (baseFaces.Count() == 0)
                {
                    baseFace = topFace;
                }
                else
                {
                    baseFace = baseFaces.OrderByDescending(u => {
                        var uv = u.BoxUV;
                        return(Math.Abs(uv.MinU - uv.MaxU) * Math.Abs(uv.MaxV - uv.MinV));
                    }).FirstOrDefault();
                }
            }

            if (topFace == null)
            {
                topFace = baseFace;
            }

            //基准点
            var basePoints = Snap.Globals.WorkPart.Points.Where(u => u.Layer == body.Layer).ToList().OrderBy(u => Snap.Compute.Distance(u.Position, body)).ToList();

            basePoint = basePoints.FirstOrDefault();
            var tempBasePoint = basePoints.FirstOrDefault(u => u.MatchAttrValue(XKElectrode.ATTR_NAME_MARK, body.Name) && u.MatchAttrValue(XKElectrode.DIM_PT, XKElectrode.DIM_PT));

            if (tempBasePoint != null)
            {
                basePoint = tempBasePoint;
            }

            if (basePoint == null && baseFace != null)
            {
                pos = baseFace.GetCenterPoint();
            }
            else if (basePoint != null)
            {
                pos = basePoint.Position;
            }
        }