示例#1
0
 public Position(Snap.NX.Point pt)
 {
     NXOpen.Point nXOpenPoint = pt.NXOpenPoint;
     this.X = nXOpenPoint.Coordinates.X;
     this.Y = nXOpenPoint.Coordinates.Y;
     this.Z = nXOpenPoint.Coordinates.Z;
 }
示例#2
0
 void UpdateEactElec(Snap.NX.Body body)
 {
     Snap.NX.Face  topFace   = null;
     Snap.NX.Face  baseFace  = null;
     Snap.NX.Point basePoint = null;
     Snap.Position pos       = new Snap.Position();
     ElecManage.Electrode.GetEactElectrode(body, ref topFace, ref baseFace, ref basePoint, ref pos);
     topFace  = selectTopFace.SelectedObjects.FirstOrDefault() as Snap.NX.Face;
     baseFace = selectBaseFace.SelectedObjects.FirstOrDefault() as Snap.NX.Face;
     pos      = selectBaseFacePointEx.Position;
     if (basePoint == null)
     {
         basePoint       = Snap.Create.Point(pos);
         basePoint.Layer = body.Layer;
         basePoint.Color = System.Drawing.Color.Green;
     }
     else
     {
         basePoint.Position = pos;
     }
     ElecManage.Electrode.SetEactElectrode(body, ref topFace, ref baseFace, ref basePoint);
 }
示例#3
0
    void SetEactElec(Snap.NX.Body body, Snap.NX.Face baseFace = null, Snap.NX.Face topFace = null, Snap.NX.Point basePoint = null)
    {
        selectBaseFace.SelectedObjects = new Snap.NX.NXObject[] { };
        selectTopFace.SelectedObjects  = new Snap.NX.NXObject[] { };
        selectBaseFacePointEx.Position = new Snap.Position();
        var pos = new Snap.Position();

        ElecManage.Electrode.GetEactElectrode(body, ref topFace, ref baseFace, ref basePoint, ref pos);
        if (baseFace != null)
        {
            selectBaseFace.SelectedObjects = new Snap.NX.NXObject[] { baseFace };
        }
        if (topFace != null)
        {
            selectTopFace.SelectedObjects = new Snap.NX.NXObject[] { topFace };
        }
        selectBaseFacePointEx.Position = pos;
        if (baseFace != null && topFace != null)
        {
            //更新尺寸
            var info = GetElecInfo(body);
            if (info != null)
            {
                strElecSize.Value        = info.ElecSize;
                strElecCuttingSize.Value = info.ElecCuttingSize(_configData, EactConfig.MatchJiaju.GetMatchJiajuValue(_configData, cbbChuckType.SelectedIndex));
            }
            else if (groupSElec.Show) //异形电极
            {
                var tempInfo = new ElecManage.ElectrodeInfo(body);
                var tempOri  = new Snap.Orientation(-baseFace.GetFaceDirection());
                strElecSize.Value        = tempInfo.GetElecSize(tempOri);
                strElecCuttingSize.Value = tempInfo.ElecCuttingSize(_configData, EactConfig.MatchJiaju.GetMatchJiajuValue(_configData, cbbChuckType.SelectedIndex), tempOri);
            }
            else
            {
                strElecSize.Value        = string.Empty;
                strElecCuttingSize.Value = string.Empty;
            }
        }
    }
示例#4
0
    void Perform(bool isHighlighted = false)
    {
        var workPart  = theSession.Parts.Work;
        var body      = selection0.SelectedObjects.FirstOrDefault() as Snap.NX.Body;
        var jiajuBody = selectionJiaju.SelectedObjects.FirstOrDefault() as Snap.NX.Body;

        tempObjs.ForEach(u => {
            Snap.NX.NXObject snapU = u;
            snapU.Delete();
        });
        tempObjs.Clear();

        if (body != null)
        {
            Snap.NX.Body snapBody = body;
            //电极原点
            var tempElecOrigin = SnapEx.Helper.GetElecMidPosition(workPart, body);
            if (tempElecOrigin == null)
            {
                theUI.NXMessageBox.Show("提示", NXOpen.NXMessageBox.DialogType.Information, "该电极未发现基准点!");
                return;
            }
            var elecOrgin = (Snap.Position)tempElecOrigin;


            if (isHighlighted)
            {
                SnapEx.Create.DisplayModification(tempObjs);
            }

            bool isPatter = false;
            if (enum01.SelectedItem == "平移")
            {
                isPatter = toggleMovePatter.Value;
            }
            else
            {
                isPatter = toggleRotationPatter.Value;
            }
            int sum = 0;

            if (isPatter)
            {
                sum = (int)(expressionPatterSum.Value < 0?0:expressionPatterSum.Value);
            }

            double distance = expressionPatterDistance.Value;
            var    vector   = Snap.Vector.Unit(vectorPatter.Direction);

            if (body.NXOpenBody.OwningComponent != null && snapBody.Prototype != null)
            {
                var snapComponent = snapBody.OwningComponent;;
                NXOpen.Assemblies.Component component = snapComponent;


                var transForm = GetTransform(elecOrgin);

                for (int i = 0; i < sum + 1; i++)
                {
                    Snap.NX.Component newComponent = workPart.ComponentAssembly.CopyComponents(new List <NXOpen.Assemblies.Component> {
                        component
                    }.ToArray()).First();
                    newComponent.Prototype.Bodies.First().SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now);
                    tempObjs.Add(newComponent);

                    //平移旋转
                    var       trans  = transForm.Matrix;
                    Matrix3x3 matrix = new Matrix3x3();
                    matrix.Xx = trans[0]; matrix.Xy = trans[4]; matrix.Xz = trans[8];
                    matrix.Yx = trans[1]; matrix.Yy = trans[5]; matrix.Yz = trans[9];
                    matrix.Zx = trans[2]; matrix.Zy = trans[6]; matrix.Zz = trans[10];
                    workPart.ComponentAssembly.MoveComponent(newComponent, new Vector3d(trans[3], trans[7], trans[11]), matrix);

                    if (i != 0)
                    {
                        workPart.ComponentAssembly.MoveComponent(newComponent, (distance * i) * vector, new Snap.Orientation());
                    }
                }
            }
            else
            {
                NXOpen.Point point = null;
                if (!isHighlighted)
                {
                    var tempPoint = SnapEx.Helper.GetElecMidPointInPart(Snap.Globals.WorkPart, snapBody);
                    if (tempPoint != null)
                    {
                        point = tempPoint;
                    }
                }
                for (int i = 0; i < sum + 1; i++)
                {
                    var newBody = snapBody.Copy();
                    var guid    = Guid.NewGuid().ToString();
                    newBody.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid);
                    newBody.SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now);
                    tempObjs.Add(newBody);
                    var transForm = GetTransform(elecOrgin);
                    if (i != 0)
                    {
                        transForm = Snap.Geom.Transform.Composition(transForm, Snap.Geom.Transform.CreateTranslation((distance * i) * vector));
                    }

                    newBody.Move(transForm);
                    if (point != null)
                    {
                        Snap.NX.Point newPoint = Snap.NX.Point.Wrap(point.Tag).Copy();
                        newPoint.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid);
                        newPoint.Move(transForm);
                    }
                }
            }

            if (toggleJiaju.Value && jiajuBody != null)
            {
                for (int i = 0; i < sum + 1; i++)
                {
                    Snap.NX.Body snapJiajuBody = jiajuBody;
                    var          newJiajuBody  = snapJiajuBody.Copy();
                    var          guid          = Guid.NewGuid().ToString();
                    newJiajuBody.Layer = body.Layer;
                    newJiajuBody.SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now);
                    tempObjs.Add(newJiajuBody);
                    elecOrgin = new Snap.Position((snapBody.Box.MaxX + snapBody.Box.MinX) / 2, (snapBody.Box.MaxY + snapBody.Box.MinY) / 2, snapBody.Box.MinZ);
                    var transForm = GetTransform(elecOrgin);
                    if (i != 0)
                    {
                        transForm = Snap.Geom.Transform.Composition(transForm, Snap.Geom.Transform.CreateTranslation((distance * i) * vector));
                    }

                    newJiajuBody.Move(transForm);
                }
            }


            if (isHighlighted)
            {
                SnapEx.Create.DisplayModification(tempObjs);
            }
        }
    }