Exemple #1
0
    void InitModelingView(EdmDraw.EdmConfig edmConfig, ElecManage.Electrode elec, bool isAutoMode = true)
    {
        if (IsInitModelingView && !isAutoMode)
        {
            return;
        }
        SnapEx.Create.ApplicationSwitchRequest(SnapEx.ApplicationType.MODELING);
        var wcsOrientation     = Electrode.GetStandardOrientation(Snap.Globals.WcsOrientation);
        var acsOrientation     = Snap.Orientation.Identity;
        var baseDirOrientation = Electrode.GetSidelongOrientation(new Snap.Orientation(-elec.BaseFace.GetFaceDirection()));
        var transR             = Snap.Geom.Transform.CreateRotation(acsOrientation, wcsOrientation);
        var transR1            = Snap.Geom.Transform.CreateRotation(baseDirOrientation, wcsOrientation);
        var draftViewLocations = edmConfig.DraftViewLocations ?? new List <EdmDraw.EdmConfig.DraftViewLocation>();

        foreach (var item in draftViewLocations)
        {
            var viewType = EdmDraw.DrawBusiness.GetEumnViewType(item.ViewType);
            var X        = new Snap.Vector(item.Xx, item.Xy, item.Xz).Copy(transR);
            var Y        = new Snap.Vector(item.Yx, item.Yy, item.Yz).Copy(transR);
            if (viewType == EdmDraw.ViewType.EACT_BOTTOM ||
                viewType == EdmDraw.ViewType.EACT_BOTTOM_FRONT ||
                viewType == EdmDraw.ViewType.EACT_BOTTOM_ISOMETRIC
                )
            {
                X = X.Copy(transR1);
                Y = Y.Copy(transR1);
            }
            EdmDraw.DrawBusiness.CreateCamera(viewType, new double[] { X.X, X.Y, X.Z, Y.X, Y.Y, Y.Z });
        }
        IsInitModelingView = true;
    }
Exemple #2
0
        /// <summary>
        /// 获取拔模角度
        /// </summary>
        public static double GetDraftAngle(this Snap.NX.Face face, Snap.Vector draftVector)
        {
            var result = 0.0;
            var angles = new List <double>();
            var vector = new Snap.Vector(double.NaN, double.NaN, double.NaN);

            switch (face.ObjectSubType)
            {
            case Snap.NX.ObjectTypes.SubType.FacePlane:
                vector = face.GetFaceDirection();
                break;
            }

            if (double.IsNaN(vector.X) || double.IsNaN(vector.Y) || double.IsNaN(vector.Z))
            {
                var posLst = SnapEx.Create.GetFacePoints(face);
                posLst.ForEach(u => {
                    angles.Add(90 - Snap.Vector.Angle(draftVector, GetFaceDirectionByPoint(face, u)));
                });
            }
            else
            {
                angles.Add(90 - Snap.Vector.Angle(draftVector, vector));
            }

            if (angles.Count > 0)
            {
                int count = angles.Count;
                angles.ForEach(u => {
                    result += u / count;
                });
            }

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 获取平面投影面积
        /// </summary>
        public static double GetPlaneProjectArea(this Snap.NX.Face face, Snap.Vector baseDir)
        {
            var topFaceDir         = -baseDir;
            var topFaceOrientation = new Snap.Orientation(topFaceDir);
            var box = SnapEx.Ex.AcsToWcsBox3d(face.BoxEx(), topFaceOrientation);

            return(System.Math.Abs(box.MinX - box.MaxX) * System.Math.Abs(box.MinY - box.MaxY));
        }
Exemple #4
0
        /// <summary>
        /// 检测是否有干涉
        /// </summary>
        PointData IsIntervene(Snap.Position p, Snap.Vector vector, ProbeData probeData)
        {
            PointData result   = null;
            var       probe    = probeData.Body;
            var       axisFace = probe.Faces.FirstOrDefault(u => u.Name == SnapEx.ConstString.CMM_INSPECTION_AXISPOINT);

            if (axisFace != null)
            {
                foreach (var ab in probeData.ABList)
                {
                    var mark          = Globals.SetUndoMark(Globals.MarkVisibility.Visible, "IsIntervene");
                    var tempAxisPoint = axisFace.Position((axisFace.BoxUV.MinU + axisFace.BoxUV.MaxU) / 2, (axisFace.BoxUV.MinV + axisFace.BoxUV.MaxV) / 2);
                    var origin        = new Snap.Position((probe.Box.MinX + probe.Box.MaxX) / 2, (probe.Box.MinY + probe.Box.MaxY) / 2, probe.Box.MaxZ);
                    var axisPoint     = origin;
                    if (SnapEx.Helper.Equals(tempAxisPoint, origin, _tolerance))
                    {
                        origin.Z    = probe.Box.MinZ + probeData.SphereRadius;
                        axisPoint.Z = probe.Box.MaxZ;
                    }
                    else
                    {
                        axisPoint.Z = probe.Box.MinZ;
                        origin.Z    = probe.Box.MaxZ - probeData.SphereRadius;
                    }
                    //A角
                    origin.Move(Snap.Geom.Transform.CreateRotation(axisPoint, _orientation.AxisX, ab.A));
                    probe.Move(Snap.Geom.Transform.CreateRotation(axisPoint, _orientation.AxisX, ab.A));
                    //B角
                    origin.Move(Snap.Geom.Transform.CreateRotation(axisPoint, _orientation.AxisZ, ab.B));
                    probe.Move(Snap.Geom.Transform.CreateRotation(axisPoint, _orientation.AxisZ, ab.B));

                    var tempP = p + (probeData.SphereRadius * vector);
                    probe.Move(Snap.Geom.Transform.CreateTranslation(tempP - origin));

                    var r = SnapEx.Create.SimpleInterference(probe, _body);
                    Globals.UndoToMark(mark, null);
                    if (r == NXOpen.GeometricAnalysis.SimpleInterference.Result.OnlyEdgesOrFacesInterfere)
                    {
                        result = new PointData()
                        {
                            Vector = vector, Position = p, A = ab.A, B = ab.B, Arrow = probeData.ProbeName
                        };
                        break;
                    }
                }
            }



            return(result);
        }
Exemple #5
0
        /// <summary>
        /// 创建箭头
        /// </summary>
        public static Snap.NX.Body CreateArrows(Snap.Position origin, Snap.Vector vector)
        {
            return(Snap.Create.DatumAxis(origin, vector).Body);
            //var cylinder = Snap.Create.Cylinder(origin, vector, 40, 0.5);
            //origin = origin + (40 * vector);

            //var baseDiameter = 2.5;
            //var topDiameter = 0.0;
            //var cone = Snap.Create.Cone(origin, vector, new Number[] { baseDiameter, topDiameter }, 5);
            //var body = cone.Body;
            //var unite = Snap.Create.Unite(body, cylinder.Body);
            //unite.Orphan();
            //body.Color = System.Drawing.Color.Black;
            //return body;
        }
Exemple #6
0
        /// <summary>
        /// 移动对象
        /// </summary>
        public static void MoveObject(NXOpen.NXObject obj, Snap.Position point, Snap.Vector normal, double distance)
        {
            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            NXOpen.Features.MoveObjectBuilder moveObjectBuilder1;
            moveObjectBuilder1 = workPart.BaseFeatures.CreateMoveObjectBuilder(null);
            moveObjectBuilder1.ObjectToMoveObject.Add(obj);
            moveObjectBuilder1.TransformMotion.DistanceVector      = workPart.Directions.CreateDirection(point, normal, SmartObject.UpdateOption.WithinModeling);
            moveObjectBuilder1.TransformMotion.DistanceValue.Value = distance;
            moveObjectBuilder1.MoveObjectResult       = NXOpen.Features.MoveObjectBuilder.MoveObjectResultOptions.MoveOriginal;
            moveObjectBuilder1.TransformMotion.Option = NXOpen.GeometricUtilities.ModlMotion.Options.Distance;
            moveObjectBuilder1.Commit();
            moveObjectBuilder1.Destroy();
        }
Exemple #7
0
        public static List <ProbeData.AB> OrderProbeDataAB(List <ProbeData.AB> abs, Snap.Position p, Snap.Vector pV)
        {
            var axisZ = Snap.Orientation.Identity.AxisZ;
            Func <ProbeData.AB, double> getAngleAction = (ab) => {
                var angle = Snap.Vector.Angle(pV, axisZ.Copy(GetTrans(p, ab)));
                return(angle);
            };
            var result = abs.OrderBy(u => getAngleAction(u)).ToList();

            return(result);
        }
Exemple #8
0
        /// <summary>
        /// 阵列组件
        /// </summary>
        public static NXOpen.Assemblies.ComponentPattern ComponentPattern(Snap.NX.Component component, Snap.Vector vector, double copiesCount, double pitchDistance)
        {
            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            NXOpen.Assemblies.ComponentPattern        nullAssemblies_ComponentPattern = null;
            NXOpen.Assemblies.ComponentPatternBuilder componentPatternBuilder1;
            componentPatternBuilder1 = workPart.ComponentAssembly.CreateComponentPatternBuilder(nullAssemblies_ComponentPattern);
            componentPatternBuilder1.ComponentPatternSet.Add(component);

            //矢量
            Point3d   origin3 = new Point3d(0.0, 0.0, 0.0);
            Direction direction2;

            direction2 = workPart.Directions.CreateDirection(origin3, vector, NXOpen.SmartObject.UpdateOption.WithinModeling);
            componentPatternBuilder1.PatternService.RectangularDefinition.XDirection = direction2;

            //间距
            componentPatternBuilder1.PatternService.RectangularDefinition.XSpacing.NCopies.Value       = copiesCount;
            componentPatternBuilder1.PatternService.RectangularDefinition.XSpacing.PitchDistance.Value = pitchDistance;

            nullAssemblies_ComponentPattern = componentPatternBuilder1.Commit() as NXOpen.Assemblies.ComponentPattern;
            componentPatternBuilder1.Destroy();

            return(nullAssemblies_ComponentPattern);
        }
Exemple #9
0
    void CreateDrawingSheet(Snap.NX.Body selectedObj, Snap.NX.Body steel, string templateName)
    {
        var workPart = Snap.Globals.WorkPart;
        var dsName   = selectedObj.Name;
        var list     = new List <NXOpen.TaggedObject>();

        list.Add(steel);
        list.Add(selectedObj);

        workPart.NXOpenPart.DrawingSheets.ToArray().Where(u => u.Name == dsName).ToList().ForEach(u =>
        {
            Snap.NX.NXObject.Delete(u);
        });

        //新建图纸页
        var ds = SnapEx.Create.DrawingSheet(selectedObj.Name, templateName);

        EdmDraw.DrawBusiness.SetDrawSheetLayer(ds, 254);

        //获取电极信息
        var electrode = ElecManage.Electrode.GetElectrode(selectedObj);

        if (electrode == null)
        {
            throw new Exception("无法识别该电极!");
        }
        electrode.InitAllFace();
        var topFace  = electrode.TopFace;
        var baseFace = electrode.BaseFace;
        //BASE_SIDE
        var baseSideFaces = electrode.BaseSideFaces;
        //ELECTRODE_FACE
        var electrodeFaces = electrode.ElecHeadFaces;

        var topView         = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_TOP).Tag, list, new Snap.Position(56, 72), new Snap.Position(90, 90));
        var frontView       = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_FRONT).Tag, list, new Snap.Position(56, 155), new Snap.Position(90, 40));
        var bottomFrontView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_BOTTOM_FRONT).Tag, new List <TaggedObject> {
            selectedObj
        }, new Snap.Position(154, 155), new Snap.Position(40, 40));
        var bottomView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_BOTTOM).Tag, new List <TaggedObject> {
            selectedObj
        }, new Snap.Position(154, 100), new Snap.Position(60, 60));
        var bottomIsometricView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_BOTTOM_ISOMETRIC).Tag, new List <TaggedObject> {
            selectedObj
        }, new Snap.Position(154, 50), new Snap.Position(60, 60));
        var isometricView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_ISOMETRIC).Tag, new List <NXOpen.TaggedObject> {
            steel
        }, new Snap.Position(220, 58), new Snap.Position(60, 60));
        var originPoint   = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(Snap.Globals.Wcs.Origin)); }, frontView.Tag);
        var elecBasePoint = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(electrode.GetElecBasePos())); }, frontView.Tag);


        var bottomFrontViewBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomFrontView, selectedObj);

        var bottomFrontViewTopPoint    = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomFrontViewBorderPoints[3])); }, bottomFrontView.Tag);
        var bottomFrontViewBottomPoint = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomFrontViewBorderPoints[2])); }, bottomFrontView.Tag);

        var bottomViewBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomView, selectedObj);

        var yPlusSideFace  = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewBorderPoints[1])); }, bottomFrontView.Tag);
        var yMinusSideFace = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewBorderPoints[0])); }, bottomFrontView.Tag);
        var xPlusSideFace  = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewBorderPoints[0], bottomViewBorderPoints[1])); }, bottomFrontView.Tag);
        var xMinusSideFace = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewBorderPoints[2], bottomViewBorderPoints[3])); }, bottomFrontView.Tag);

        var bottomViewElecHeadBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomView, electrodeFaces);

        var yPlusElectrodeEdge  = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewElecHeadBorderPoints[1])); }, bottomFrontView.Tag);
        var yMinusElectrodeEdge = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewElecHeadBorderPoints[0])); }, bottomFrontView.Tag);
        var xPlusElectrodeEdge  = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewElecHeadBorderPoints[0], bottomViewElecHeadBorderPoints[1])); }, bottomFrontView.Tag);
        var xMinusElectrodeEdge = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewElecHeadBorderPoints[2], bottomViewElecHeadBorderPoints[3])); }, bottomFrontView.Tag);


        //电极前视图
        EdmDraw.DrawBusiness.CreateVerticalDim(
            bottomFrontView.Tag,
            bottomFrontViewTopPoint.NXOpenTag,
            bottomFrontViewBottomPoint.NXOpenTag,
            new Snap.Position(bottomFrontView.GetDrawingReferencePoint().X + (EdmDraw.DrawBusiness.GetBorderSize(bottomFrontView.Tag).X / 2), bottomFrontView.GetDrawingReferencePoint().Y));

        EdmDraw.DrawBusiness.CreateVerticalDim(bottomFrontView.Tag, baseFace.NXOpenTag, bottomFrontViewBottomPoint.NXOpenTag,
                                               new Snap.Position(bottomFrontView.GetDrawingReferencePoint().X - (EdmDraw.DrawBusiness.GetBorderSize(bottomFrontView.Tag).X / 2), bottomFrontView.GetDrawingReferencePoint().Y));

        //电极仰视图
        EdmDraw.DrawBusiness.CreateVerticalDim(bottomView.Tag, yPlusSideFace.NXOpenTag, yMinusSideFace.NXOpenTag,
                                               new Snap.Position(bottomView.GetDrawingReferencePoint().X + (EdmDraw.DrawBusiness.GetBorderSize(bottomView.Tag).X / 2), bottomView.GetDrawingReferencePoint().Y, 0));
        EdmDraw.DrawBusiness.CreatePerpendicularDim(bottomView.Tag, xPlusSideFace.NXOpenTag, xMinusSideFace.NXOpenTag,
                                                    new Snap.Position(bottomView.GetDrawingReferencePoint().X, bottomView.GetDrawingReferencePoint().Y + (EdmDraw.DrawBusiness.GetBorderSize(bottomView.Tag).Y / 2), 0));

        EdmDraw.DrawBusiness.CreateVerticalDim(bottomView.Tag, yPlusElectrodeEdge.NXOpenTag, yMinusElectrodeEdge.NXOpenTag,
                                               new Snap.Position(bottomView.GetDrawingReferencePoint().X - (EdmDraw.DrawBusiness.GetBorderSize(bottomView.Tag).X / 2), bottomView.GetDrawingReferencePoint().Y, 0));
        EdmDraw.DrawBusiness.CreatePerpendicularDim(bottomView.Tag, xPlusElectrodeEdge.NXOpenTag, xMinusElectrodeEdge.NXOpenTag,
                                                    new Snap.Position(bottomView.GetDrawingReferencePoint().X, bottomView.GetDrawingReferencePoint().Y - (EdmDraw.DrawBusiness.GetBorderSize(bottomView.Tag).Y / 2), 0));

        var frontViewTopMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Right, frontView);
        var tempMap            = new double[] { 0, 0 };
        var ufSession          = NXOpen.UF.UFSession.GetUFSession();

        ufSession.View.MapModelToDrawing(frontView.Tag, elecBasePoint.Position.Array, tempMap);
        var basePointMTD = tempMap.ToArray();

        ufSession.View.MapModelToDrawing(frontView.Tag, originPoint.Position.Array, tempMap);
        var originPointMTD = tempMap.ToArray();
        var distance       = Snap.Compute.Distance(new Snap.Position(tempMap.First(), tempMap.Last()), frontViewTopMargin);

        EdmDraw.DrawBusiness.CreatePerpendicularOrddimension(
            frontView.Tag,
            originPoint.NXOpenTag,
            frontViewTopMargin.NXOpenTag,
            originPoint.NXOpenTag
            );
        //TODO 坐标尺寸位置问题
        var configData = 8;

        Snap.Vector v     = new Snap.Vector(distance, 0);
        Snap.Vector v1    = new Snap.Vector(distance, configData);
        var         angle = Snap.Vector.Angle(v, v1);

        Snap.Position?origin = null;
        if (basePointMTD.Last() > originPointMTD.Last())
        {
            var line = frontViewTopMargin as Snap.NX.Line;
            origin = new Snap.Position(line.StartPoint.X, originPointMTD.Last() + (configData * 2));
        }
        var frontViewOrddimension = EdmDraw.DrawBusiness.CreatePerpendicularOrddimension(
            frontView.Tag,
            originPoint.NXOpenTag,
            frontViewTopMargin.NXOpenTag,
            elecBasePoint.NXOpenTag,
            angle,
            origin
            );

        EdmDraw.DrawBusiness.SetToleranceType(frontViewOrddimension);



        var topViewRightMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Right, topView);
        var topViewTopMargin   = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Top, topView);

        var topViewRightElecBasePoint = EdmDraw.DrawBusiness.CreatePerpendicularOrddimension(
            topView.Tag,
            originPoint.NXOpenTag,
            topViewRightMargin.NXOpenTag,
            elecBasePoint.NXOpenTag
            );

        EdmDraw.DrawBusiness.SetToleranceType(topViewRightElecBasePoint);

        EdmDraw.DrawBusiness.CreatePerpendicularOrddimension(
            topView.Tag,
            originPoint.NXOpenTag,
            topViewRightMargin.NXOpenTag,
            originPoint.NXOpenTag
            );

        var topViewTopElecBasePoint = EdmDraw.DrawBusiness.CreateVerticalOrddimension(
            topView.Tag,
            originPoint.NXOpenTag,
            topViewTopMargin.NXOpenTag,
            elecBasePoint.NXOpenTag
            );

        EdmDraw.DrawBusiness.SetToleranceType(topViewTopElecBasePoint);

        EdmDraw.DrawBusiness.CreateVerticalOrddimension(
            topView.Tag,
            originPoint.NXOpenTag,
            topViewTopMargin.NXOpenTag,
            originPoint.NXOpenTag
            );

        EdmDraw.DrawBusiness.GetBorderPoint(topView, steel).ForEach(u =>
        {
            var tempU = EdmDraw.DrawBusiness.CreateNxObject <Snap.NX.Point>(() => { return(Snap.Create.Point(u)); }, topView.Tag);
            EdmDraw.DrawBusiness.CreateVerticalOrddimension(
                topView.Tag,
                originPoint.NXOpenTag,
                topViewTopMargin.NXOpenTag,
                tempU.NXOpenTag
                );

            EdmDraw.DrawBusiness.CreatePerpendicularOrddimension(
                topView.Tag,
                originPoint.NXOpenTag,
                topViewRightMargin.NXOpenTag,
                tempU.NXOpenTag
                );
        });

        var borderSize = topView.GetBorderSize();
        var refPoint   = topView.GetDrawingReferencePoint();

        EdmDraw.DrawBusiness.CreateIdSymbol("C1", new Snap.Position(refPoint.X - (borderSize.X / 2), refPoint.Y), new Snap.Position(), topView.Tag, elecBasePoint.NXOpenTag);

        //注释
        EdmDraw.DrawBusiness.CreateNode(selectedObj.Name, new Snap.Position(35, 19));

        //表格
        EdmDraw.DrawBusiness.CreateTabnot(new Snap.Position(216, ds.Height - 1.5), 2, 4, 15, 15);

        EdmDraw.DrawBusiness.CreatePentagon(new Snap.Position(223, ds.Height - 1.5 - 2), QuadrantType.Four);
    }
Exemple #10
0
        static PointData IsIntervene(ElecManage.Electrode elec, Snap.Position p, Snap.Vector pV, List <Snap.NX.Curve> curves, CMMConfig config, PointType pointType = PointType.UNKOWN, bool isBaseFace = false)
        {
            PointData result      = null;
            var       targetBody  = elec.ElecBody;
            var       maxZ        = config.ElecMaxZ + config.SafeDistance;
            var       minDistance = Helper.GetPointToEdgeMinDistance(p, curves);
            var       ProbeDatas  = config.ProbeDatas ?? new List <ProbeData>();

            if (isBaseFace)
            {
                var probeData = ProbeDatas.FirstOrDefault(u => u.IsBaseFaceProbe);
                if (probeData != null)
                {
                    ProbeDatas = new List <ProbeData> {
                        probeData
                    };
                }
            }

            foreach (var data in ProbeDatas)
            {
                if (result != null)
                {
                    break;
                }
                //过滤探球半径的点
                if (minDistance < config.MinEdgeDistance)
                {
                    continue;
                }
                var abs = data.GetABList(p, pV);
                foreach (var ab in abs)
                {
                    var toolBody         = data.GetBody(ab);
                    var lstTrans         = new List <Snap.Geom.Transform>();
                    var centreOfSphere   = data.GetCentreOfSphere(ab);
                    var inspectionPoints = new List <Position>();

                    //退点
                    var sRetreatPosition = p.Copy(Snap.Geom.Transform.CreateTranslation((data.D / 2) * pV));
                    lstTrans.Add(Snap.Geom.Transform.CreateTranslation(sRetreatPosition - centreOfSphere));
                    var mRetreatPosition = sRetreatPosition.Copy(Snap.Geom.Transform.CreateTranslation(config.RetreatPoint * pV));
                    lstTrans.Add(Snap.Geom.Transform.CreateTranslation(mRetreatPosition - sRetreatPosition));
                    var fRetreatPosition = new Snap.Position(mRetreatPosition.X, mRetreatPosition.Y, maxZ);
                    //lstTrans.Add(Snap.Geom.Transform.CreateTranslation(fRetreatPosition - mRetreatPosition));
                    if (config.RetreatPoint != config.EntryPoint)
                    {
                        //逼进拐点
                        var sEntryPosition = sRetreatPosition.Copy(Snap.Geom.Transform.CreateTranslation(config.EntryPoint * pV));
                        if (config.EntryPoint > 0)
                        {
                            lstTrans.Add(Snap.Geom.Transform.CreateTranslation(sEntryPosition - mRetreatPosition));
                        }
                        var fEntryPosition = new Snap.Position(sEntryPosition.X, sEntryPosition.Y, maxZ);
                        inspectionPoints.Add(fEntryPosition);
                        inspectionPoints.Add(sEntryPosition);
                    }
                    inspectionPoints.Add(sRetreatPosition);
                    inspectionPoints.Add(mRetreatPosition);
                    inspectionPoints.Add(fRetreatPosition);
                    if (config.IsInspectionPath)
                    {
                        if (data.CheckInspectionPath(ab, inspectionPoints, targetBody))
                        {
                            continue;
                        }
                    }
                    bool isHasInterference = false;
                    foreach (var trans in lstTrans)
                    {
                        toolBody.Move(trans);
                        if (Helper.CheckInterference(targetBody.NXOpenTag, toolBody.NXOpenTag))
                        {
                            isHasInterference = true;
                            break;
                        }
                    }

                    if (!isHasInterference)
                    {
                        result = new PointData()
                        {
                            Vector = pV, Position = p, A = ab.A, B = ab.B, Arrow = data.ProbeName
                        };
                        result.PointType = pointType;
                        break;
                    }
                }
            }

            return(result);
        }
Exemple #11
0
    public override void Apply()
    {
        EleAutoCam.NxopenCAM.CreateCAM();
        return;

        var ufSession = NXOpen.UF.UFSession.GetUFSession();

        Session theSession  = Session.GetSession();
        Part    workPart    = theSession.Parts.Work;
        Part    displayPart = theSession.Parts.Display;

        Snap.NX.Part snapPart = workPart;
        double[]     param    = new double[2], point = new double[3], u1 = new double[3], v1 = new double[3], u2 = new double[3], v2 = new double[3], unitNorm = new double[3], radii = new double[2];

        //分析几何体,得到平面,直面,斜面,曲面,并对其分类着色
        snapPart.Bodies.First().Faces.ToList().ForEach(u =>
        {
            ufSession.Modl.AskFaceProps(u.NXOpenTag, param, point, u1, v1, u2, v2, unitNorm, radii);
            var unitNormAbs0 = System.Math.Abs(unitNorm[0]);
            var unitNormAbs1 = System.Math.Abs(unitNorm[1]);
            var unitNormAbs2 = System.Math.Abs(unitNorm[2]);
            switch (u.NXOpenFace.SolidFaceType)
            {
            case Face.FaceType.Planar:
                {
                    if (0.00001 > unitNormAbs0 && 0.00001 > unitNormAbs1 && 0.99999 < unitNorm[2])    //平面颜色
                    {
                        u.Color = System.Drawing.Color.Blue;
                    }
                    else if (0.00001 < unitNorm[2] && unitNorm[2] < 1)    //斜面颜色
                    {
                        u.Color = System.Drawing.Color.Red;
                    }
                    else if (0.00001 > unitNormAbs2)    //直面颜色
                    {
                        u.Color = System.Drawing.Color.Brown;
                    }
                    else if (-0.00001 > unitNorm[2] && unitNorm[2] > -1)    //无法加工的面
                    {
                        u.Color = System.Drawing.Color.BurlyWood;
                    }
                    else if (unitNorm[2] < -0.99999)    //无法加工的面
                    {
                        u.Color = System.Drawing.Color.CadetBlue;
                    }
                    break;
                }

            default:
                {
                    if (0.00001 < unitNorm[2])     //曲面
                    {
                        u.Color = System.Drawing.Color.Aqua;
                    }
                    else if (0.00001 > unitNormAbs2)    //直面
                    {
                        u.Color = System.Drawing.Color.Beige;
                    }
                    else if (-0.00001 > unitNormAbs2)    //无法加工的面
                    {
                        u.Color = System.Drawing.Color.Bisque;
                    }
                    break;
                }
            }
        });
        templateTypeName = "ElectrodeAutoCam";

        //进入CAM模块
        theSession.CreateCamSession();
        //初始化CAM
        var cAMSetup1 = workPart.CreateCamSetup(templateTypeName);

        //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);

        //TODO 创建坐标系和几何体
        NXOpen.Tag workMcsGroupTag;
        ufSession.Ncgeom.Create("mill_planar", "MCS", out workMcsGroupTag);
        ufSession.Obj.SetName(workMcsGroupTag, "GEOM_PH");
        ufSession.Ncgroup.AcceptMember(geometryGroupRootTag, workMcsGroupTag);

        //TODO 设置安全平面
        var normal = new Snap.Vector(0, 0, 1);
        var origin = new Snap.Position();

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

        //TODO 创建几何体
        ufSession.Ncgeom.Create(templateTypeName, "WORKPIECE", out workGeometryGroupTag);
        ufSession.Obj.SetName(workGeometryGroupTag, "WORKPIECE_PH");
        ufSession.Ncgroup.AcceptMember(workMcsGroupTag, workGeometryGroupTag);

        //TODO 添加Body作为工作几何体
        SnapEx.CAMEx.SetMillArea(NXOpen.UF.CamGeomType.CamPart, workGeometryGroupTag, new List <Tag> {
            workPart.Bodies.ToArray().First().Tag
        });

        //TODO 设置毛坯为自动块
        ufSession.Cam.SetAutoBlank(workGeometryGroupTag, NXOpen.UF.UFCam.BlankGeomType.AutoBlockType, new double[] { 0, 0, 0, 0, 0, 0 });

        //TODO 创建程序
        NXOpen.Tag programGroupTag;
        ufSession.Ncprog.Create(templateTypeName, "PROGRAM", out programGroupTag);
        ufSession.Obj.SetName(programGroupTag, "PROGRAM_PH");
        ufSession.Ncgroup.AcceptMember(orderGroupRootTag, programGroupTag);

        //TODO 创建Cut,并设置相应的参数
        NXOpen.Tag cutterTag;
        ufSession.Cutter.Create(templateTypeName, "MILL", out cutterTag);
        ufSession.Ncgroup.AcceptMember(cutterGroupRootTag, cutterTag);
        ufSession.Obj.SetName(cutterTag, "PH_TOOL1");
        ufSession.Param.SetDoubleValue(cutterTag, NXOpen.UF.UFConstants.UF_PARAM_TL_DIAMETER, 6);


        //TODO 创建工序
        NXOpen.Tag operTag;
        ufSession.Oper.Create(templateTypeName, "FACE_MILLING_KC", out operTag);//铣顶面
        ufSession.Ncgroup.AcceptMember(workGeometryGroupTag, operTag);
        ufSession.Ncgroup.AcceptMember(programGroupTag, operTag);
        ufSession.Ncgroup.AcceptMember(methodGroupRootTag, operTag);
        ufSession.Ncgroup.AcceptMember(cutterTag, operTag);

        //TODO 指定面边界
        var electrode = ElecManage.XKElectrode.GetElectrode(snapPart.Bodies.First());

        if (electrode != null && electrode.ElecHeadFaces.Count > 0)
        {
            var headFace = electrode.ElecHeadFaces.OrderBy(u => Snap.Compute.Distance(new Snap.Position(), u)).FirstOrDefault();
            SnapEx.CAMEx.SetBoundaryByFace(NXOpen.UF.CamGeomType.CamBlank, operTag, headFace.NXOpenTag, NXOpen.UF.CamMaterialSide.CamMaterialSideInLeft);

            SnapEx.CAMEx.PathGenerate(new List <Tag> {
                operTag
            });
        }
    }