コード例 #1
0
        public static object GetReferenceEntityEx(this ISketch ske, out swSelectType_e entityType)
        {
            int entityType_int = 0;
            var obj            = ske.GetReferenceEntity(ref entityType_int);

            entityType = entityType_int.CastObj <swSelectType_e>();
            return(obj);
        }
コード例 #2
0
        private void CreateSegments(IEnumerable <IXSketchEntity> segments, ISketch sketch)
        {
            var addToDbOrig = m_SkMgr.AddToDB;

            m_Sketch.SetEditMode(sketch, true);

            m_SkMgr.AddToDB = true;

            foreach (SwSketchEntity seg in segments)
            {
                seg.Commit();
            }

            m_SkMgr.AddToDB = addToDbOrig;

            m_Sketch.SetEditMode(sketch, false);
        }
コード例 #3
0
 public void SetEditMode(ISketch sketch, bool isEditing)
 {
     if (isEditing)
     {
         if (!GetEditMode(sketch))
         {
             //TODO: use API only selection
             (sketch as IFeature).Select2(false, 0);
             ToggleEditSketch();
         }
     }
     else
     {
         if (GetEditMode(sketch))
         {
             ToggleEditSketch();
         }
     }
 }
コード例 #4
0
 public ISketchObject(ISketch ISketchinstance)
 {
     ISketchInstance = ISketchinstance;
 }
コード例 #5
0
        internal void CommitCache(ISketch sketch)
        {
            CreateSegments(m_Cache, sketch);

            m_Cache.Clear();
        }
コード例 #6
0
        public void CreateHeaterCenter(string heaterPathName)
        {
            ISketchPoint       startPoint = null;
            ISketchPoint       endPoint   = null;
            List <SegmentData> list       = new List <SegmentData>();
            List <SegmentData> list2      = new List <SegmentData>();
            List <SegmentData> list3      = new List <SegmentData>();
            List <SegmentData> list4      = new List <SegmentData>();

            _swApp.ActivateDoc(_swPartModel.GetTitle());
            _swPartModel.ShowNamedView2("*Front", 1);

            ISketchArc arc;
            double     length;

            list2.Clear();
            list.Clear();
            _swPartModel.Extension.SelectByID2(heaterPathName, "SKETCH", 0.0, 0.0, 0.0, true, 0, null, 0);
            _swPartModel.ViewZoomToSelection();
            ISelectionMgr iSelectionManager = _swPartModel.ISelectionManager;

            IFeature feature = iSelectionManager.GetSelectedObject6(1, 0);

            ISketch sketch = feature.GetSpecificFeature2();

            Array array = sketch.GetSketchSegments();

            Array array2 = sketch.GetSketchPoints2();

            foreach (ISketchSegment segment in array)
            {
                ISketchSegment segment2 = segment;
                segment2.Select(true);
                if (!segment2.ConstructionGeometry)
                {
                    if (segment2.GetType() == 0)
                    {
                        ISketchLine line = (ISketchLine)segment2;
                        startPoint = line.IGetStartPoint2();
                        endPoint   = line.IGetEndPoint2();
                    }
                    if (segment2.GetType() == 1)
                    {
                        arc        = (ISketchArc)segment2;
                        startPoint = arc.IGetStartPoint2();
                        endPoint   = arc.IGetEndPoint2();
                    }
                    SegmentData item = new SegmentData(segment2, startPoint, endPoint);
                    list.Add(item);
                }
                _swPartModel.ClearSelection2(true);
            }
            for (int i = 0; i < list.Count; i++)
            {
                int num9 = 0;
                list2.Add(list[0]);
                list.Remove(list[0]);
                for (int m = 0; m < list.Count; m++)
                {
                    list2[0].Segment.Select(false);
                    list[m].Segment.Select(false);
                    if ((Math.Round(list2[0].StartPoint.X, 5) == Math.Round(list[m].StartPoint.X, 5)) && (Math.Round(list2[0].StartPoint.Y, 5) == Math.Round(list[m].StartPoint.Y, 5)))
                    {
                        num9++;
                    }
                    if ((Math.Round(list2[0].EndPoint.X, 5) == Math.Round(list[m].EndPoint.X, 5)) && (Math.Round(list2[0].EndPoint.Y, 5) == Math.Round(list[m].EndPoint.Y, 5)))
                    {
                        num9++;
                    }
                    if ((Math.Round(list2[0].EndPoint.X, 5) == Math.Round(list[m].StartPoint.X, 5)) && (Math.Round(list2[0].EndPoint.Y, 5) == Math.Round(list[m].StartPoint.Y, 5)))
                    {
                        num9++;
                    }
                    if ((Math.Round(list2[0].StartPoint.X, 5) == Math.Round(list[m].EndPoint.X, 5)) && (Math.Round(list2[0].StartPoint.Y, 5) == Math.Round(list[m].EndPoint.Y, 5)))
                    {
                        num9++;
                    }
                    _swPartModel.ClearSelection2(true);
                    if (num9 == 2)
                    {
                        list.Add(list2[0]);
                        list2.Remove(list2[0]);
                        break;
                    }
                }
                if (num9 == 1)
                {
                    list2[0].Segment.Select(true);
                    break;
                }
            }
            int num = 0;

            for (int j = 0; j < list.Count; j++)
            {
                list2[num].Segment.Select(true);
                list[j].Segment.Select(false);
                if ((Math.Round(list2[num].StartPoint.X, 5) == Math.Round(list[j].StartPoint.X, 5)) && (Math.Round(list2[num].StartPoint.Y, 5) == Math.Round(list[j].StartPoint.Y, 5)))
                {
                    list2.Add(list[j]);
                    list.Remove(list[j]);
                    num++;
                    j = -1;
                }
                else if ((Math.Round(list2[num].EndPoint.X, 5) == Math.Round(list[j].EndPoint.X, 5)) && (Math.Round(list2[num].EndPoint.Y, 5) == Math.Round(list[j].EndPoint.Y, 5)))
                {
                    list2.Add(list[j]);
                    list.Remove(list[j]);
                    num++;
                    j = -1;
                }
                else if ((Math.Round(list2[num].EndPoint.X, 5) == Math.Round(list[j].StartPoint.X, 5)) && (Math.Round(list2[num].EndPoint.Y, 5) == Math.Round(list[j].StartPoint.Y, 5)))
                {
                    list2.Add(list[j]);
                    list.Remove(list[j]);
                    num++;
                    j = -1;
                }
                else if ((Math.Round(list2[num].StartPoint.X, 5) == Math.Round(list[j].EndPoint.X, 5)) && (Math.Round(list2[num].StartPoint.Y, 5) == Math.Round(list[j].EndPoint.Y, 5)))
                {
                    list2.Add(list[j]);
                    list.Remove(list[j]);
                    num++;
                    j = -1;
                }
            }
            _swPartModel.ClearSelection();
            _swPartModel.Extension.SelectByID2(heaterPathName, "SKETCH", 0.0, 0.0, 0.0, false, 0, null, 0);
            _swPartModel.EditSketch();
            foreach (ISketchPoint point3 in array2)
            {
                point3.Select(false);
                if (point3.Type == 1)
                {
                    _swPartModel.EditDelete();
                }
            }
            double num2 = 0.0;

            foreach (SegmentData data2 in list2)
            {
                data2.Segment.Select(false);
                length = data2.Segment.GetLength();
                num2  += length;
            }
            _swPartModel.ClearSelection();
            double num4 = num2 / 2.0;

            length = 0.0;
            int    num5 = 0;
            double num6 = 0.0;

            for (int k = 0; k < list2.Count; k++)
            {
                list2[k].Segment.Select(false);
                length += list2[k].Segment.GetLength();
                if (num4 < length)
                {
                    num5 = k;
                    double num7 = Math.Abs((double)(length - num4));
                    num6 = (list2[num5].Segment.GetLength() - num7) / list2[num5].Segment.GetLength();
                    break;
                }
            }
            _swPartModel.ClearSelection();
            if (list2[num5].Segment.GetType() == 0)
            {
                double num13 = 0.0;
                double x     = list2[num5].StartPoint.X;
                double y     = list2[num5].StartPoint.Y;
                double num16 = list2[num5].EndPoint.X;
                double num17 = list2[num5].EndPoint.Y;
                if ((Math.Round(num16, 6) == Math.Round(list2[num5 - 1].StartPoint.X, 6)) && (Math.Round(num17, 6) == Math.Round(list2[num5 - 1].StartPoint.Y, 6)))
                {
                    num16 = list2[num5].StartPoint.X;
                    num17 = list2[num5].StartPoint.Y;
                    x     = list2[num5].EndPoint.X;
                    y     = list2[num5].EndPoint.Y;
                }
                else if ((Math.Round(num16, 6) == Math.Round(list2[num5 - 1].EndPoint.X, 6)) && (Math.Round(num17, 6) == Math.Round(list2[num5 - 1].EndPoint.Y, 6)))
                {
                    num16 = list2[num5].StartPoint.X;
                    num17 = list2[num5].StartPoint.Y;
                    x     = list2[num5].EndPoint.X;
                    y     = list2[num5].EndPoint.Y;
                }
                double pointX = x + ((num16 - x) * num6);
                double pointY = y + ((num17 - y) * num6);
                _swPartModel.SetAddToDB(true);
                if (_swPartModel.CreatePoint2(pointX, pointY, 0.0) != null)
                {
                    _swPartModel.SketchAddConstraints("sgFixed");
                }
                if (x == num16)
                {
                    num13 = 1.5707963267948966;
                }
                if (y == num17)
                {
                    num13 = 3.1415926535897931;
                }
                if ((x != num16) && !(y == num17))
                {
                    num13 = Math.Atan((num17 - y) / (num16 - x));
                }
                if (num13 > 3.1415926535897931)
                {
                    num13 -= 3.1415926535897931;
                }
                ISketchSegment segment3 = _swPartModel.ICreateLine2(pointX + (0.005 * Math.Cos(num13 + 1.5707963267948966)), pointY + (0.005 * Math.Sin(num13 + 1.5707963267948966)), 0.0, pointX + (0.005 * Math.Cos(num13 + 4.71238898038469)), pointY + (0.005 * Math.Sin(num13 + 4.71238898038469)), 0.0);
                _swPartModel.SketchAddConstraints("sgFIXED");
                segment3.ConstructionGeometry = true;
                _swPartModel.SetAddToDB(false);
                _swPartModel.ClearSelection2(true);
                _swPartModel.InsertSketch2(true);
            }
            if (list2[num5].Segment.GetType() == 1)
            {
                arc        = (ISketchArc)list2[num5].Segment;
                startPoint = arc.IGetStartPoint2();
                endPoint   = arc.IGetEndPoint2();
                ISketchPoint point4      = arc.IGetCenterPoint2();
                int          rotationDir = arc.GetRotationDir();
                double       num21       = 0.0;
                double       num22       = 0.0;
                double       num23       = list2[num5].Segment.GetLength();
                double       radius      = arc.GetRadius();
                double       num25       = (num6 * num23) / radius;
                double       num26       = startPoint.X;
                double       num27       = startPoint.Y;
                double       num28       = endPoint.X;
                double       num29       = endPoint.Y;
                double       num30       = point4.X;
                double       num31       = point4.Y;
                if ((Math.Round(num28, 6) == Math.Round(list2[num5 - 1].StartPoint.X, 6)) && (Math.Round(num29, 6) == Math.Round(list2[num5 - 1].StartPoint.Y, 6)))
                {
                    num26       = endPoint.X;
                    num27       = endPoint.Y;
                    rotationDir = -1 * rotationDir;
                }
                else if ((Math.Round(num28, 6) == Math.Round(list2[num5 - 1].EndPoint.X, 6)) && (Math.Round(num29, 6) == Math.Round(list2[num5 - 1].EndPoint.Y, 6)))
                {
                    num26       = endPoint.X;
                    num27       = endPoint.Y;
                    rotationDir = -1 * rotationDir;
                }
                if ((num30 != num26) && !(num31 == num27))
                {
                    num21 = Math.Atan((num31 - num27) / (num30 - num26));
                }
                if (Math.Round(num30, 8) == Math.Round(num26, 8))
                {
                    if (Math.Round(num31, 8) > Math.Round(num27, 8))
                    {
                        num21 = 4.71238898038469;
                    }
                    else if (Math.Round(num31, 8) < Math.Round(num27, 8))
                    {
                        num21 = 1.5707963267948966;
                    }
                }
                else if (Math.Round(num31, 8) == Math.Round(num27, 8))
                {
                    if (Math.Round(num30, 8) > Math.Round(num26, 8))
                    {
                        num21 = 3.1415926535897931;
                    }
                    else if (Math.Round(num30, 8) < Math.Round(num26, 8))
                    {
                        if (rotationDir > 0)
                        {
                            num21 = 0.0;
                        }
                        else
                        {
                            num21 = 6.2831853071795862;
                        }
                    }
                }
                if ((Math.Round(num30, 8) < Math.Round(num26, 8)) && (Math.Round(num31, 8) < Math.Round(num27, 8)))
                {
                    num22 = num21 + (rotationDir * num25);
                }
                else if ((Math.Round(num30, 8) < Math.Round(num26, 8)) && (Math.Round(num31, 8) > Math.Round(num27, 8)))
                {
                    num22 = (6.2831853071795862 + num21) + (rotationDir * num25);
                }
                else if ((Math.Round(num30, 8) > Math.Round(num26, 8)) && (Math.Round(num31, 8) > Math.Round(num27, 8)))
                {
                    num22 = (3.1415926535897931 + num21) + (rotationDir * num25);
                }
                else if ((Math.Round(num30, 8) > Math.Round(num26, 8)) && (Math.Round(num31, 8) < Math.Round(num27, 8)))
                {
                    num22 = (3.1415926535897931 + num21) + (rotationDir * num25);
                }
                else if (Math.Round(num30, 8) == Math.Round(num26, 8))
                {
                    num22 = num21 + (rotationDir * num25);
                }
                else if (Math.Round(num31, 8) == Math.Round(num27, 8))
                {
                    num22 = num21 + (rotationDir * num25);
                }
                num22 = Math.Round(num22, 6);
                double num32  = num30 + (radius * Math.Cos(num22));
                double num33  = num31 + (radius * Math.Sin(num22));
                bool   flag29 = true;
                if (_swPartModel.Extension.SelectByID2("", "SKETCHPOINT", num32, num33, 0.0, false, 0, null, 0))
                {
                    ISketchPoint point5 = iSelectionManager.GetSelectedObject6(0, 1);

                    if ((point5 != null) && ((Math.Round(point5.X, 6) == Math.Round(num32, 6)) && (Math.Round(point5.Y, 6) == Math.Round(num33, 6))))
                    {
                        flag29 = false;
                    }
                }
                _swPartModel.SetAddToDB(true);
                if (flag29 && (_swPartModel.CreatePoint2(num32, num33, 0.0) != null))
                {
                    _swPartModel.SketchAddConstraints("sgFIXED");
                    _swPartModel.ICreateLine2(num30, num31, 0.0, num32, num33, 0.0).ConstructionGeometry = true;
                }
                _swPartModel.SetAddToDB(false);
                _swPartModel.ClearSelection2(true);
                _swPartModel.InsertSketch2(true);
            }
        }
コード例 #7
0
 public bool GetEditMode(ISketch sketch)
 {
     return(OwnerModelDoc.SketchManager.ActiveSketch == sketch);
 }
コード例 #8
0
        /// <summary>
        /// 检测草图可用的特征
        /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_BASEEXTRUDE"/>:基本拉伸特征
        /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_BASEEXTRUDETHIN"/>: 基本薄壁拉伸特征
        /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_BOSSREVOLVE"/>:基本旋转特征
        /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_LOFTSECTION"/>:放样草图块
        /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_LOFTGUIDE"/>:放样引导线草图
        /// </summary>
        /// <param name="ske"><see cref="ISketch"/> Interface</param>
        /// <param name="featProfileType"><see cref="swSketchCheckFeatureProfileUsage_e"/></param>
        /// <returns>Tuple result
        /// Item1: <see cref="swSketchCheckFeatureStatus_e"/>
        /// Item2: <see cref="int"/> OpenCount 开环数量
        /// Item3: <see cref="int"/> ClosedCount 闭环数量
        /// </returns>
        public static Tuple <swSketchCheckFeatureStatus_e, int, int> CheckFeatureUseEx(this ISketch ske, swSketchCheckFeatureProfileUsage_e featProfileType)
        {
            int openCount   = 0;
            int closedCount = 0;
            var status      = ske.CheckFeatureUse(featProfileType.SWToInt(), ref openCount, ref
                                                  closedCount).CastObj <swSketchCheckFeatureStatus_e>();

            return(new Tuple <swSketchCheckFeatureStatus_e, int, int>(status, openCount, closedCount));
        }
コード例 #9
0
 /// <summary>
 /// 检测草图可用的特征
 /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_BASEEXTRUDE"/>:基本拉伸特征
 /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_BASEEXTRUDETHIN"/>: 基本薄壁拉伸特征/>
 /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_BOSSREVOLVE"/>:基本旋转特征/>
 /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_LOFTSECTION"/>:放样草图块/>
 /// <see cref="swSketchCheckFeatureProfileUsage_e.swSketchCheckFeature_LOFTGUIDE"/>:放样引导线草图/>
 /// </summary>
 /// <param name="ske"><see cref="ISketch"/></param>
 /// <param name="featProfileType"><see cref="swSketchCheckFeatureProfileUsage_e"/> Interface</param>
 /// <param name="openCount">开环数量</param>
 /// <param name="closedCount">闭环数量</param>
 /// <returns><see cref="swSketchCheckFeatureStatus_e"/></returns>
 public static swSketchCheckFeatureStatus_e CheckFeatureUseEx(this ISketch ske, swSketchCheckFeatureProfileUsage_e featProfileType, ref int openCount, ref int closedCount)
 {
     return(ske.CheckFeatureUse(featProfileType.SWToInt(), ref openCount, ref closedCount).CastObj <swSketchCheckFeatureStatus_e>());
 }
コード例 #10
0
 /// <summary>
 /// 将 <see cref="ISketch"/> 转换为 IFeature
 /// </summary>
 /// <param name="sketch"><see cref="IFeature"/></param>
 /// <returns></returns>
 public static IFeature AsFeature(this ISketch sketch)
 {
     return(sketch as IFeature);
 }
コード例 #11
0
 /// <summary>
 /// 获取所有的草图实体
 /// </summary>
 /// <param name="ske"><see cref="ISketch"/> Interface</param>
 /// <returns></returns>
 public static IEnumerable <ISketchSegment> GetSketchSegmentsEx(this ISketch ske)
 {
     return((ske.GetSketchSegments() as object[]).Cast <ISketchSegment>());
 }
コード例 #12
0
 internal bool GetEditMode(ISketch sketch)
 {
     return(m_ModelDoc.SketchManager.ActiveSketch == sketch);
 }