Exemplo n.º 1
0
        private TransCAD.Reference GetTargetFace(PARTITF.Hole hole)
        {
            object[] axis = new object[9];

            hole.Sketch.GetAbsoluteAxisData(axis);

            TransCAD.Reference targetFace = PartManager.tPart.SelectPlaneByAxis((double)axis[0], (double)axis[1], (double)axis[2],
                                                                                (double)axis[3], (double)axis[4], (double)axis[5],
                                                                                (double)axis[6], (double)axis[7], (double)axis[8]);

            return(targetFace);
        }
Exemplo n.º 2
0
        // Pre
        public override void TranslateC2T(MECMOD.Shape cShape)
        {
            PARTITF.Hole hole = (PARTITF.Hole)cShape;

            double diameter     = 0.0;
            double depth        = 0.0;
            double bottomAngle  = 180.0;
            double headDiameter = 0.0;
            double headAngle    = 0.0;
            double headDepth    = 0.0;

            object[] org = new object[3];
            hole.GetOrigin(org);

            diameter = hole.Diameter.Value;
            depth    = hole.BottomLimit.Dimension.Value;

            if (hole.BottomType == PARTITF.CatHoleBottomType.catVHoleBottom)
            {
                bottomAngle = hole.BottomAngle.Value;
            }

            if (hole.Type == PARTITF.CatHoleType.catCounterboredHole)
            {
                headDiameter = hole.HeadDiameter.Value;
                headDepth    = hole.HeadDepth.Value;

                PartManager.tFeatures.AddNewSolidHoleCounterboredFeature(hole.get_Name(), GetTargetFace(hole), (double)org[0], (double)org[1], (double)org[2], headDiameter / 2, headDepth, diameter / 2, depth - headDepth, bottomAngle);
            }
            else if (hole.Type == PARTITF.CatHoleType.catCountersunkHole)
            {
                headDepth = hole.HeadDepth.Value;
                headAngle = hole.HeadAngle.Value;

                headDiameter = diameter + 2 * Math.Tan(headAngle / 2 * Math.PI / 180) * headDepth;

                PartManager.tFeatures.AddNewSolidHoleCountersunkFeature(hole.get_Name(), GetTargetFace(hole), (double)org[0], (double)org[1], (double)org[2], diameter / 2, depth, headDiameter / 2, headAngle, bottomAngle);
            }
            else if (hole.Type == PARTITF.CatHoleType.catSimpleHole)
            {
                PartManager.tFeatures.AddNewSolidHoleSimpleFeature(hole.get_Name(), GetTargetFace(hole), (double)org[0], (double)org[1], (double)org[2], diameter / 2, depth);
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            DRAFTINGITF.DrawingDocument DrwDoc  = null;
            DRAFTINGITF.DrawingView     DrwView = null;

            try
            {
                DrwDoc = (DRAFTINGITF.DrawingDocument)catia.ActiveDocument;
            }
            catch (Exception)
            {
                MessageBox.Show("please open a DrawingDocument");
                return;
            }

            DRAFTINGITF.DrawingRoot DrwRoot = DrwDoc.DrawingRoot;

            try
            {
                DrwView = DrwRoot.ActiveSheet.Views.Item(DrwRoot.ActiveSheet.Views.Count);
            }
            catch (Exception)
            {
                MessageBox.Show("sheet가 없습니다.");
                return;
            }
            DRAFTINGITF.DrawingViewGenerativeBehavior DrwGenBeh = DrwView.GenerativeBehavior;

            double X1, Y1, Z1, X2, Y2, Z2;

            DrwGenBeh.GetProjectionPlane(out X1, out Y1, out Z1, out X2, out Y2, out Z2);

            ProductStructureTypeLib.Product Prd    = (ProductStructureTypeLib.Product)DrwGenBeh.Document;
            MECMOD.PartDocument             PrtDoc = (MECMOD.PartDocument)Prd.ReferenceProduct.Parent;
            MECMOD.Part Prt = PrtDoc.Part;

            MECMOD.Body   Bdy  = Prt.MainBody;
            MECMOD.Shapes Shps = Bdy.Shapes;

            PARTITF.Hole tHole = (PARTITF.Hole)Shps.GetItem("Hole.1");
            object[]     opt   = new object[3];
            tHole.GetOrigin(opt);
            //radiuse
            //tHole.

            //3D 위치 값
            // double X = -37.935, Y = 96.8, Z = 104.207;
            double X = (double)opt[0];
            double Y = (double)opt[1];
            double Z = (double)opt[2];

            //결과 값
            double COS_ALPHA = 0, VW_H = 0, VW_V = 0;

            //계산과정
            COS_ALPHA = (X * X1 + Y * Y1 + Z * Z1) / ((Math.Pow(X1, 2) + Math.Pow(Y1, 2) + Math.Pow(Z1, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_H      = Math.Sqrt(X * X + Y * Y + Z * Z) * COS_ALPHA;

            COS_ALPHA = (X * X2 + Y * Y2 + Z * Z2) / ((Math.Pow(X2, 2) + Math.Pow(Y2, 2) + Math.Pow(Z2, 2)) * Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)));
            VW_V      = Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2)) * COS_ALPHA;

            //create the point
            MECMOD.Factory2D fac = DrwView.Factory2D;
            fac.CreatePoint(VW_H, VW_V);

            //add a text (20정도 뛰어보자)

            DRAFTINGITF.DrawingText txt = DrwView.Texts.Add("Hole( " + (int)X + " , " + (int)Y + " , " + (int)Z + " )", VW_H + 20, VW_V - 20);
            // DRAFTINGITF.DrawingText txt = DrwView.Texts.Add(("( {0} , {1} , {2} )"X,Y,Z), VW_H + 20, VW_V - 20);
            txt.SetFontSize(0, 0, 12);

            DRAFTINGITF.DrawingLeader FDleadr = txt.Leaders.Add(VW_H, VW_V);

            //update the drawing document.
            DrwDoc.Update();
        }
Exemplo n.º 4
0
        // Post
        public override void TranslateT2C(TransCAD.IFeature tFeature)
        {
            double diameter     = 0.0;
            double depth        = 0.0;
            double bottomAngle  = 180.0;
            double headDiameter = 0.0;
            double headAngle    = 0.0;
            double headDepth    = 0.0;

            double[] org = new double[3];

            PARTITF.Hole cHole = null;

            if (tFeature.Type == TransCAD.FeatureType.StdSolidHoleSimpleFeature)
            {
                TransCAD.IStdSolidHoleSimpleFeature tHoleSimple = (TransCAD.IStdSolidHoleSimpleFeature)tFeature;
                tHoleSimple.CenterPoint(out org[0], out org[1], out org[2]);
                depth    = tHoleSimple.Depth;
                diameter = tHoleSimple.Radius * 2;
                INFITF.Reference targetFace = GetTargetFace(tHoleSimple.TargetFace.ReferenceeName);

                cHole      = PartManager.cShapeFactory.AddNewHole(targetFace, 10.0);
                cHole.Type = PARTITF.CatHoleType.catSimpleHole;
                cHole.SetOrigin(org[0], org[1], org[2]);
                cHole.BottomLimit.Dimension.Value = depth;
                cHole.Diameter.Value = diameter;

                PartManager.ReferenceManager.NameMap.Add(tHoleSimple.Name, cHole.get_Name());
            }
            else if (tFeature.Type == TransCAD.FeatureType.StdSolidHoleCounterboredFeature)
            {
                TransCAD.StdSolidHoleCounterboredFeature tHoleCounterbored = (TransCAD.StdSolidHoleCounterboredFeature)tFeature;
                tHoleCounterbored.CenterPoint(out org[0], out org[1], out org[2]);
                headDepth    = tHoleCounterbored.StartDepth;
                headDiameter = tHoleCounterbored.StartRadius * 2;
                depth        = tHoleCounterbored.EndDepth + headDepth;
                diameter     = tHoleCounterbored.EndRadius * 2;
                bottomAngle  = tHoleCounterbored.Angle;
                INFITF.Reference targetFace = GetTargetFace(tHoleCounterbored.TargetFace.ReferenceeName);

                cHole      = PartManager.cShapeFactory.AddNewHole(targetFace, 10.0);
                cHole.Type = PARTITF.CatHoleType.catCounterboredHole;
                cHole.SetOrigin(org[0], org[1], org[2]);
                cHole.HeadDepth.Value             = headDepth;
                cHole.HeadDiameter.Value          = headDiameter;
                cHole.BottomLimit.Dimension.Value = depth;
                cHole.Diameter.Value = diameter;

                PartManager.ReferenceManager.NameMap.Add(tHoleCounterbored.Name, cHole.get_Name());
            }
            else if (tFeature.Type == TransCAD.FeatureType.StdSolidHoleCountersunkFeature)
            {
                TransCAD.IStdSolidHoleCountersunkFeature tHoleCountersunk = (TransCAD.IStdSolidHoleCountersunkFeature)tFeature;
                tHoleCountersunk.CenterPoint(out org[0], out org[1], out org[2]);
                headAngle    = tHoleCountersunk.SinkAngle;
                headDiameter = tHoleCountersunk.SinkRadius * 2;
                depth        = tHoleCountersunk.Depth;
                diameter     = tHoleCountersunk.Radius * 2;
                headDepth    = 0.5 * (headDiameter - diameter) / Math.Tan(0.5 * headAngle * Math.PI / 180);

                bottomAngle = tHoleCountersunk.BottomAngle;
                INFITF.Reference targetFace = GetTargetFace(tHoleCountersunk.TargetFace.ReferenceeName);

                cHole                 = PartManager.cShapeFactory.AddNewHole(targetFace, 10.0);
                cHole.Type            = PARTITF.CatHoleType.catCountersunkHole;
                cHole.CounterSunkMode = PARTITF.CatCSHoleMode.catCSModeAngleDiameter;
                cHole.SetOrigin(org[0], org[1], org[2]);
                cHole.HeadAngle.Value             = headAngle;
                cHole.HeadDepth.Value             = headDepth;
                cHole.BottomLimit.Dimension.Value = depth;
                cHole.Diameter.Value = diameter;

                PartManager.ReferenceManager.NameMap.Add(tHoleCountersunk.Name, cHole.get_Name());
            }

            if (bottomAngle != 180.0)
            {
                cHole.BottomType        = PARTITF.CatHoleBottomType.catVHoleBottom;
                cHole.BottomAngle.Value = bottomAngle;
            }

            PartManager.cPart.UpdateObject(cHole);
        }