public static IEnumerable <ObjectSelection> GetObjectSelections(this ISelectionMgr selMgr)
        {
            var count = selMgr.GetSelectedObjectCount2(AnyMark);

            selMgr.EnableContourSelection = true;
            return(Enumerable.Range(StartIndex, count)
                   .Select(index =>
            {
                var type = (swSelectType_e)selMgr.GetSelectedObjectType3(index, AnyMark);
                var mark = selMgr.GetSelectedObjectMark(index);
                var obj = selMgr.GetSelectedObject6(index, AnyMark);
                //var typeList = ComWangling.GetComTypeFor<Surface>(obj).ToList();

                //LogViewer.Log($"Type of selection is {string.Join(", ", typeList)}");

                //if (type==swSelectType_e.swSelREFEDGES || type == swSelectType_e.swSelEDGES)
                //{
                //    var edge = obj.DirectCast<IEdge>();
                //}else if (type == swSelectType_e.swSelHELIX)
                //{
                //    var foo = obj.DirectCast<IFeature>();
                //}

                return new ObjectSelection(obj, type, mark, index);
            }));
        }
 /// <summary>
 /// Get selected objects filtered by type and mark
 /// </summary>
 /// <param name="selMgr"></param>
 /// <param name="filter"> <![CDATA[(type,mark)=>bool]]> if null then the default is true </param>
 /// <returns></returns>
 public static IReadOnlyList <object> GetSelectedObjects(this ISelectionMgr selMgr, Func <swSelectType_e, int, bool> filter)
 {
     return(selMgr.GetObjectSelections()
            .Where(o => filter(o.Type, o.Mark))
            .Select(o => o.Object)
            .ToList());
 }
Exemplo n.º 3
0
        public void Main()
        {
            List <DispatchWrapper> swObjects = new List <DispatchWrapper>();

            IModelDoc2 model = swApp.IActiveDoc2;

            if (model != null)
            {
                ISelectionMgr selMgr = model.ISelectionManager;

                for (int i = 0; i < selMgr.GetSelectedObjectCount2(-1); i++)
                {
                    object swSelObj = selMgr.GetSelectedObject6(i + 1, -1);
                    swObjects.Add(new DispatchWrapper(swSelObj));//it is required to wrap dispatch pointers to allow selection of objects of different types (i.e. faces, annotations, components etc.) together
                }

                model.ClearSelection2(true);

                Debugger.Break();

                model.Extension.MultiSelect2(swObjects.ToArray(), false, null);
            }
            else
            {
                swApp.SendMsgToUser("Please open the model");
            }
        }
 /// <summary>
 /// .ctor
 /// </summary>
 /// <param name="object">对象</param>
 /// <param name="type">类型</param>
 /// <param name="mark">标记</param>
 /// <param name="index">序号</param>
 /// <param name="selecMgr">管理器</param>
 public ObjectSelection(object @object, swSelectType_e type, int mark, int index, ref ISelectionMgr selecMgr)
 {
     Object    = @object;
     Index     = index;
     Type      = type;
     Mark      = mark;
     _selecMgr = selecMgr;
 }
        internal SelectionGroup(ISelectionMgr selMgr)
        {
            if (selMgr == null)
            {
                throw new ArgumentNullException(nameof(selMgr));
            }

            m_SelMgr = selMgr;

            m_SelMgr.SuspendSelectionList();
        }
        /// <summary>
        /// 获取选中对象
        /// </summary>
        /// <param name="selMgr"></param>
        /// <returns></returns>
        public static IEnumerable <ObjectSelection> GetObjectSelections(this ISelectionMgr selMgr)
        {
            var count = selMgr.GetSelectedObjectCount();

            for (int i = 1; i < count + 1; i++)
            {
                int            selMark        = selMgr.GetSelectedObjectMark(i);
                swSelectType_e swSelectType_E = (swSelectType_e)selMgr.GetSelectedObjectType3(i, AnyMark);
                object         obj            = selMgr.GetSelectedObject6(i, AnyMark);
                yield return(new ObjectSelection(obj, swSelectType_E, selMark, i, ref selMgr));
            }
        }
Exemplo n.º 7
0
        public static IEnumerable <ObjectSelection> GetObjectSelections(this ISelectionMgr selMgr)
        {
            var count = selMgr.GetSelectedObjectCount2(AnyMark);

            return(Enumerable.Range(StartIndex, count)
                   .Select(index =>
            {
                var type = (swSelectType_e)selMgr.GetSelectedObjectType3(index, AnyMark);
                var mark = selMgr.GetSelectedObjectMark(index);
                var obj = selMgr.GetSelectedObject6(index, AnyMark);
                return new ObjectSelection(obj, type, mark, index);
            }));
        }
        /// <summary>
        /// 获取所有的选择对象
        /// </summary>
        /// <param name="selMgr"></param>
        /// <param name="Mark"></param>
        /// <returns></returns>
        public static List <ObjectSelection> GetAllSelectedObjectsEx(this ISelectionMgr selMgr)
        {
            var count = selMgr.GetSelectedObjectCount();
            List <ObjectSelection> objList = new List <ObjectSelection>();

            for (int i = 1; i < count + 1; i++)
            {
                int            selMark        = selMgr.GetSelectedObjectMark(i);
                swSelectType_e swSelectType_E = (swSelectType_e)selMgr.GetSelectedObjectType3(i, AnyMark);
                object         obj            = selMgr.GetSelectedObject6(i, AnyMark);
                objList.Add(new ObjectSelection(obj, swSelectType_E, selMark, i));
            }
            return(objList);
        }
        /// <summary>
        /// 获取选中对象
        /// </summary>
        /// <param name="selMgr"></param>
        /// <returns></returns>
        public static IEnumerable <ObjectSelection> GetObjectSelections(this ISelectionMgr selMgr)
        {
            return(GetAllSelectedObjectsEx(selMgr));

            //var count = selMgr.GetSelectedObjectCount2(AnyMark);
            //selMgr.EnableContourSelection = true;
            //return Enumerable.Range(StartIndex, count)
            //    .Select(index =>
            //    {
            //        var type = (swSelectType_e)selMgr.GetSelectedObjectType3(index, AnyMark);
            //        var mark = selMgr.GetSelectedObjectMark(index);
            //        var obj = selMgr.GetSelectedObject6(index, AnyMark);


            //        return new ObjectSelection(obj, type, mark, index);
            //    });
        }
Exemplo n.º 10
0
        //画第二个草图,中点重合即可.

        private Feature DrawnSketchOnFace(ModelDoc2 swModel, double[] mousePoint, string SketchName, Entity swSelFaceEntity)
        {
            swModel.SketchManager.InsertSketch(true);

            //通过两条相邻边来标注 创建点的位置

            //1。 计算鼠标选中点到面的各边的距离。

            //Dictionary<Edge, double> pointToEdgeDim = new Dictionary<Edge, double>();

            var selMousePt = (double[])TransformPoint(swModel.IGetActiveSketch2(), mousePoint[0], mousePoint[1], mousePoint[2]);

            swModel.SketchManager.CreateCenterRectangle(selMousePt[0], selMousePt[1], selMousePt[2], selMousePt[0] + 0.03, selMousePt[1] + 0.03, selMousePt[2]);

            swModel.ClearSelection2(true);

            swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, false, 0, null, 0);

            swModel.Extension.SelectByID2("Point1@" + SketchName, "EXTSKETCHPOINT", 0, 0, 0, true, 0, null, 0);

            swModel.SketchAddConstraints("sgCOINCIDENT");//增加重合

            var skFeature = (Feature)swModel.IGetActiveSketch2();

            swModel.SketchManager.InsertSketch(true);

            var boolstatus = swModel.InsertPlanarRefSurface();

            ISelectionMgr swSelMgr = (ISelectionMgr)swModel.SelectionManager;

            skFeature = (Feature)swSelMgr.GetSelectedObject6(1, 0);// swModel.FeatureByPositionReverse(0);

            return(skFeature);
            //skFeature = swModel.FeatureByPositionReverse(0);

            //return skFeature;
        }
Exemplo n.º 11
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button1.Text    = "Proceeding...";
            // preventing empty fields
            if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) ||
                string.IsNullOrWhiteSpace(textBox3.Text) || string.IsNullOrWhiteSpace(textBox4.Text) ||
                string.IsNullOrWhiteSpace(textBox5.Text) || string.IsNullOrWhiteSpace(textBox6.Text) ||
                string.IsNullOrWhiteSpace(textBox7.Text) || string.IsNullOrWhiteSpace(textBox8.Text))
            {
                MessageBox.Show("Enter all values", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int    time    = Convert.ToInt32(textBox1.Text);
            int    step    = Convert.ToInt32(textBox2.Text);
            int    initt1  = Convert.ToInt32(textBox3.Text);
            int    initt2  = Convert.ToInt32(textBox4.Text);
            int    initt3  = Convert.ToInt32(textBox7.Text);
            int    conv    = Convert.ToInt32(textBox5.Text);
            double bulk    = Convert.ToDouble(textBox8.Text) + 273.15; // converting to Kelvin units
            int    heatpow = Convert.ToInt32(textBox6.Text);

            DisposeSW();

            // Opening SW 2017
            // Additional GUID: F16137AD-8EE8-4D2A-8CAC-DFF5D1F67522
            Guid Guid1 = new Guid("6B36082E-677B-49E8-BCB2-76698EBD2906");

            object processSW = System.Activator.CreateInstance(System.Type.GetTypeFromCLSID(Guid1));

            swApp         = (SldWorks)processSW;
            swApp.Visible = true;

            CosmosWorks           COSMOSWORKS    = default(CosmosWorks);
            CwAddincallback       CWObject       = default(CwAddincallback);
            CWModelDoc            ActDoc         = default(CWModelDoc);
            CWStudyManager        StudyMngr      = default(CWStudyManager);
            CWStudy               Study          = default(CWStudy);
            CWThermalStudyOptions ThermalOptions = default(CWThermalStudyOptions);
            CWConvection          CWConv         = default(CWConvection);
            CWMesh        CwMesh               = default(CWMesh);
            CWResults     CWResult             = default(CWResults);
            CWTemperature CWTemp               = default(CWTemperature);
            ModelDoc2     Part                 = default(ModelDoc2);
            CWLoadsAndRestraintsManager LBCMgr = default(CWLoadsAndRestraintsManager);
            CWHeatPower CWHeatPower            = default(CWHeatPower);
            ModelDoc2   swDoc        = null;
            int         bApp         = 0;
            int         longstatus   = 0;
            int         longwarnings = 0;
            int         errCode      = 0;
            double      el           = 0;
            double      tl           = 0;
            string      cwpath       = "";

            Part = swApp.OpenDoc6("G:\\assem(simple).SLDASM", (int)swDocumentTypes_e.swDocASSEMBLY,
                                  (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref longstatus, ref longwarnings);
            if (Part == null)
            {
                MessageBox.Show("Failed to open document");
            }

            swDoc = swApp.IActiveDoc2;

            // connecting Simulation to SW
            cwpath  = swApp.GetExecutablePath() + @"\Simulation\cosworks.dll";
            errCode = swApp.LoadAddIn(cwpath);
            if (errCode != 0 && errCode != 2)
            {
                MessageBox.Show("Failed to load Simulation library");
                swApp.ExitApp();
                DisposeSW();
                Application.Exit();
            }

            // ready-check Simulation add-on
            CWObject = (CwAddincallback)swApp.GetAddInObject("CosmosWorks.CosmosWorks");
            if (CWObject == null)
            {
                MessageBox.Show("Failed to start Simulation");
            }

            // ready-check add-on object
            COSMOSWORKS = CWObject.CosmosWorks;
            if (COSMOSWORKS == null)
            {
                MessageBox.Show("Failed to create CosmosWorks object");
            }

            // connecting add-on to document
            ActDoc = COSMOSWORKS.ActiveDoc;
            if (ActDoc == null)
            {
                MessageBox.Show("Failed to open document");
            }

            // creating thermal analysis
            bApp      = ActDoc.AddDefaultThermalStudyPlot((int)swsThermalResultComponentTypes_e.swsThermalResultComponentTypes_TEMP, true);
            StudyMngr = ActDoc.StudyManager;
            if (StudyMngr == null)
            {
                MessageBox.Show("Failed to start analysis manager");
            }

            Study = StudyMngr.CreateNewStudy3("CPU Usage", (int)swsAnalysisStudyType_e.swsAnalysisStudyTypeThermal,
                                              (int)swsMeshType_e.swsMeshTypeSolid, out errCode);
            if (Study == null)
            {
                MessageBox.Show("Failed to create thermal analysis");
            }

            ThermalOptions = Study.ThermalStudyOptions;
            Study.ThermalStudyOptions.SolutionType = 0;
            if (ThermalOptions == null)
            {
                MessageBox.Show("No analysis parameters");
            }

            // analysis duration
            ThermalOptions.CheckFlowConvectionCoef = 0;
            ThermalOptions.SolverType    = 2;
            ThermalOptions.TotalTime     = time;
            ThermalOptions.TimeIncrement = step;

            LBCMgr = Study.LoadsAndRestraintsManager;
            if (LBCMgr == null)
            {
                MessageBox.Show("Failed to load loads and restraints manager");
            }

            // lit coordinates
            swDoc.ShowNamedView2("*Top", 5);
            swDoc.ViewZoomtofit2();
            ISelectionMgr selectionMgr = (ISelectionMgr)swDoc.SelectionManager;
            bool          isSelected   = swDoc.Extension.SelectByRay(-0.28387922510520769, 0.081999999999993634,
                                                                     -0.14613487203691797, 0, -1, 0, 0.0047546274155552031, 2, false, 0, 0);

            if (isSelected)
            {
                Entity     swEntity  = selectionMgr.GetSelectedObject6(1, -1);
                Component2 swComp    = (Component2)swEntity.GetComponent();
                object[]   fixedpart = { swComp };
                CWTemp = LBCMgr.AddTemperature(fixedpart, out errCode);
                if (errCode != 0)
                {
                    MessageBox.Show("Failed to add temperature indicator");
                }
            }

            CWTemp.TemperatureBeginEdit();
            CWTemp.TemperatureType  = 0;
            CWTemp.Unit             = 2;
            CWTemp.TemperatureValue = initt2;

            errCode = CWTemp.TemperatureEndEdit();
            if (errCode != 0)
            {
                MessageBox.Show("Failed to edit temperature indicator");
            }

            swDoc.ClearSelection2(true);

            // silicon board coordinates
            isSelected = swDoc.Extension.SelectByRay(-0.41952594843134139, 0.02199999999999136,
                                                     -0.41742831868918501, 0, -1, 0, 0.0047546274155552031, 2, false, 0, 0);
            if (isSelected)
            {
                Entity     swEntity  = selectionMgr.GetSelectedObject6(1, -1);
                Component2 swComp    = (Component2)swEntity.GetComponent();
                object[]   fixedpart = { swComp };
                CWTemp = LBCMgr.AddTemperature(fixedpart, out errCode);
                if (errCode != 0)
                {
                    MessageBox.Show("Failed to add temperature indicator");
                }
            }

            CWTemp.TemperatureBeginEdit();
            CWTemp.TemperatureType  = 0;
            CWTemp.Unit             = 2;
            CWTemp.TemperatureValue = initt1;

            errCode = CWTemp.TemperatureEndEdit();
            if (errCode != 0)
            {
                MessageBox.Show("Failed to edit temperature indicator");
            }

            swDoc.ClearSelection2(true);

            // stalks coordinates
            swDoc.ShowNamedView2("*Bottom", 6);
            swDoc.ViewZoomtofit2();
            isSelected = swDoc.Extension.SelectByRay(-0.42931488722807265, -0.050999999999987722, 0.28597685484736474, 0, 1, 0, 0.0047546274155552031, 2, false, 0, 0);
            if (isSelected)
            {
                Entity     swEntity  = selectionMgr.GetSelectedObject6(1, -1);
                Component2 swComp    = (Component2)swEntity.GetComponent();
                object[]   fixedpart = { swComp };
                CWTemp = LBCMgr.AddTemperature(fixedpart, out errCode);
                if (errCode != 0)
                {
                    MessageBox.Show("Failed to edit temperature indicator");
                }
            }

            CWTemp.TemperatureBeginEdit();
            CWTemp.TemperatureType  = 0;
            CWTemp.Unit             = 2;
            CWTemp.TemperatureValue = initt3;

            errCode = CWTemp.TemperatureEndEdit();
            if (errCode != 0)
            {
                MessageBox.Show("Failed to edit temperature indicator");
            }

            swDoc.ClearSelection2(true);

            // all faces coordinates
            swDoc.ShowNamedView2("*Front", 1);
            swDoc.ViewZoomtofit2();
            isSelected = swDoc.Extension.SelectByRay(-0.38382731822234351, 0.04982938298755997, 0.40017589628916994, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.18695037482381383, 0.049829382987560122, 0.42176499999999351, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(0.35735646868976789, 0.0713369482327776, 0.41521684512093771, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.10505618408240869, 0.010950322736590109, 0.4415000000000191, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.43015130490435044, -0.017174954891772284, 0.29464212540386825, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(0.42932409085645729, -0.016347740843879296, 0.29483222724246616, 0, 0, -1, 0.0028125277628361371, 2, false, 0, 0);

            swDoc.ShowNamedView2("*Back", 2);
            swDoc.ViewZoomtofit2();
            isSelected = swDoc.Extension.SelectByRay(0.3581836827376611, 0.063064807753847776, -0.4148975912216315, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(0.14558967242916476, 0.053138239179132019, -0.42176499999999351, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.37969124798287845, 0.047347740843881027, -0.40327910794843547, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(0.033088561915719295, 0.012604750832376084, -0.4415000000000191, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(0.42766966276067148, -0.014693312748093316, -0.29499856062381014, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.42766966276067131, -0.022138239179130152, -0.29499856062381014, 0, 0, 1, 0.0028125277628361371, 2, false, 0, 0);

            swDoc.ShowNamedView2("*Left", 3);
            swDoc.ViewZoomtofit2();
            isSelected = swDoc.Extension.SelectByRay(-0.42176499999999351, 0.046520526795988171, -0.081066976693512371, 1, 0, 0, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.4415000000000191, 0.0084686805929112003, -0.082721404789298347, 1, 0, 0, 0.0028125277628361371, 2, false, 0, 0);

            swDoc.ShowNamedView2("*Right", 4);
            swDoc.ViewZoomtofit2();
            isSelected = swDoc.Extension.SelectByRay(0.42176499999999351, 0.052311025131239031, 0.1158099667050172, -1, 0, 0, 0.0028125277628361371, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(0.4415000000000191, 0.010123108688697121, 0.12490932123184006, -1, 0, 0, 0.0028125277628361371, 2, false, 0, 0);

            swDoc.ShowNamedView2("*Top", 5);
            swDoc.ViewZoomtofit2();
            isSelected = swDoc.Extension.SelectByRay(-0.19376272580646192, 0.081999999999993634, -0.13541980560506936, 0, -1, 0, 0.0036397418107291194, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.41535877134202892, 0.02199999999999136, -0.42017607667975893, 0, -1, 0, 0.0036397418107291194, 2, false, 0, 0);

            swDoc.ShowNamedView2("*Bottom", 6);
            swDoc.ViewZoomtofit2();
            isSelected = swDoc.Extension.SelectByRay(-0.20232682418464809, -0.00099999999997635314, 0.23818898614330264, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.42713440661203494, -0.050999999999987722, 0.28743255181787342, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(0.42713440661203483, -0.050999999999987722, 0.28529152722332685, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(0.4292754312065814, -0.050999999999987722, -0.28422101492605301, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0);
            isSelected = swDoc.Extension.SelectByRay(-0.42499338201748837, -0.050999999999987722, -0.28636203952059958, 0, 1, 0, 0.0036397418107291194, 2, false, 0, 0);
            if (isSelected)
            {
                object   selectedFace1  = (object)selectionMgr.GetSelectedObject6(1, -1);
                object   selectedFace2  = (object)selectionMgr.GetSelectedObject6(2, -1);
                object   selectedFace3  = (object)selectionMgr.GetSelectedObject6(3, -1);
                object   selectedFace4  = (object)selectionMgr.GetSelectedObject6(4, -1);
                object   selectedFace5  = (object)selectionMgr.GetSelectedObject6(5, -1);
                object   selectedFace6  = (object)selectionMgr.GetSelectedObject6(6, -1);
                object   selectedFace7  = (object)selectionMgr.GetSelectedObject6(7, -1);
                object   selectedFace8  = (object)selectionMgr.GetSelectedObject6(8, -1);
                object   selectedFace9  = (object)selectionMgr.GetSelectedObject6(9, -1);
                object   selectedFace10 = (object)selectionMgr.GetSelectedObject6(10, -1);
                object   selectedFace11 = (object)selectionMgr.GetSelectedObject6(11, -1);
                object   selectedFace12 = (object)selectionMgr.GetSelectedObject6(12, -1);
                object   selectedFace13 = (object)selectionMgr.GetSelectedObject6(13, -1);
                object   selectedFace14 = (object)selectionMgr.GetSelectedObject6(14, -1);
                object   selectedFace15 = (object)selectionMgr.GetSelectedObject6(15, -1);
                object   selectedFace16 = (object)selectionMgr.GetSelectedObject6(16, -1);
                object   selectedFace17 = (object)selectionMgr.GetSelectedObject6(17, -1);
                object   selectedFace18 = (object)selectionMgr.GetSelectedObject6(18, -1);
                object   selectedFace19 = (object)selectionMgr.GetSelectedObject6(19, -1);
                object   selectedFace20 = (object)selectionMgr.GetSelectedObject6(20, -1);
                object   selectedFace21 = (object)selectionMgr.GetSelectedObject6(21, -1);
                object   selectedFace22 = (object)selectionMgr.GetSelectedObject6(22, -1);
                object   selectedFace23 = (object)selectionMgr.GetSelectedObject6(23, -1);
                object[] fixedpart      = { selectedFace1, selectedFace2,  selectedFace3,  selectedFace4,  selectedFace5,  selectedFace6,  selectedFace7,  selectedFace8,  selectedFace9,  selectedFace10,
                                            selectedFace11,     selectedFace12, selectedFace13, selectedFace14, selectedFace15, selectedFace16, selectedFace17, selectedFace18, selectedFace19, selectedFace20,selectedFace21,
                                            selectedFace22,     selectedFace23 };
                CWConv = LBCMgr.AddConvection(fixedpart, out errCode);
                if (errCode != 0)
                {
                    MessageBox.Show("Failed to add convection coefficient indicator");
                }
            }

            CWConv.ConvectionBeginEdit();
            CWConv.Unit = 0;
            CWConv.ConvectionCoefficient  = conv;
            CWConv.BulkAmbientTemperature = bulk;

            errCode = CWConv.ConvectionEndEdit();
            if (errCode != 0)
            {
                MessageBox.Show("Failed to edit convection coefficient indicator");
            }

            swDoc.ClearSelection2(true);

            // stalks coordinates
            isSelected = swDoc.Extension.SelectByRay(-0.42931488722807265, -0.050999999999987722, 0.28597685484736474, 0, 1, 0, 0.0047546274155552031, 2, false, 0, 0);
            if (isSelected)
            {
                Entity     swEntity  = selectionMgr.GetSelectedObject6(1, -1);
                Component2 swComp    = (Component2)swEntity.GetComponent();
                object[]   fixedpart = { swComp };
                CWHeatPower = LBCMgr.AddHeatPower(fixedpart, out errCode);
                if (errCode != 0)
                {
                    MessageBox.Show("Failed to add thermal power indicator");
                }
            }

            CWHeatPower.HeatPowerBeginEdit();
            CWHeatPower.Unit              = 0;
            CWHeatPower.HPValue           = heatpow;
            CWHeatPower.ReverseDirection  = 0;
            CWHeatPower.IncludeThermostat = 0;
            errCode = CWHeatPower.HeatPowerEndEdit();
            if (errCode != 0)
            {
                MessageBox.Show("Failed to edit thermal power indicator");
            }

            swDoc.ShowNamedView2("*Isometric", 7);
            swDoc.ViewZoomtofit2();

            // creating mesh model
            CwMesh = Study.Mesh;
            if (CwMesh == null)
            {
                MessageBox.Show("No mesh model");
            }

            CwMesh.Quality = 1;
            CwMesh.GetDefaultElementSizeAndTolerance(0, out el, out tl);
            errCode = Study.CreateMesh(0, el, tl);
            if (errCode != 0)
            {
                MessageBox.Show("Failed to create mesh model");
            }

            // analysis start
            errCode = Study.RunAnalysis();
            if (errCode != 0)
            {
                MessageBox.Show("Failed to start analysi: " + errCode);
            }

            CWResult = Study.Results;
            if (CWResult == null)
            {
                MessageBox.Show("No results");
            }
            else
            {
                MessageBox.Show("Done", "Results");
                button1.Enabled = true;
                button1.Text    = "Thermal analysis";
            }
            double[] max = new double[time / step];
            double[] min = new double[time / step];
            double[] avg = new double[4];

            for (int i = 1; i <= time / step; i++)
            {
                CWPlot plot = CWResult.GetPlot("Thermal" + i.ToString(), out errCode);
                plot.SetComponentUnitAndValueByElem(0, 2, false);
                object[] results = null;
                results    = (object[])plot.GetMinMaxResultValues(out errCode);
                max[i - 1] = Convert.ToDouble(results[3].ToString());
                min[i - 1] = Convert.ToDouble(results[1].ToString());
                if (i == 1)
                {
                    avg[0] = Convert.ToDouble(results[1].ToString());
                    avg[1] = Convert.ToDouble(results[3].ToString());
                }
                if (i == time / step)
                {
                    avg[2] = Convert.ToDouble(results[1].ToString());
                    avg[3] = Convert.ToDouble(results[3].ToString());
                }
            }

            double maxValue = max.Max();
            double minValue = min.Min();

            textBox9.Text  = maxValue.ToString("#.##");
            textBox10.Text = minValue.ToString("#.##");

            double heatdens = Math.Abs(conv * (((initt2 + initt3) / 2) - (initt3 - (maxValue - minValue))));

            textBox12.Text = heatdens.ToString("#.##");

            double avg1 = (avg[0] + avg[1]) / 2;
            double avg2 = (avg[2] + avg[3]) / 2;
            double avgr = avg1 - avg2;

            textBox15.Text = avgr.ToString("#.##");
        }
Exemplo n.º 12
0
        void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            studyName = nameTextBox.Text;
            if (string.IsNullOrWhiteSpace(studyName))
            {
                studyName = "Freq_Cantilever";
            }

            analysisLabel.Invoke((MethodInvoker) delegate
            {
                analysisLabel.Visible = true;
            });

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Disposing of SW processes...";
            });

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Visible = true;
            });

            // manual cancelling of the analysis
            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            DisposeSW();

            resGrid.Invoke((MethodInvoker) delegate
            {
                resGrid.Rows.Clear();
                resGrid.Refresh();
            });

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            bwStudy.ReportProgress(5);

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Launching SW...";
            });

            object processSW = System.Activator.CreateInstance(System.Type.GetTypeFromCLSID(Guid1));

            swApp         = (SldWorks)processSW;
            swApp.Visible = true;

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Loading Simulation library...";
            });

            // connecting Simulation to SW
            cwpath  = swApp.GetExecutablePath() + @"\Simulation\cosworks.dll";
            errCode = swApp.LoadAddIn(cwpath);
            if (errCode != 0 && errCode != 2)
            {
                MessageBox.Show("Failed to load Simulation library");
                swApp.ExitApp();
                DisposeSW();
                Application.Exit();
            }

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Creating cantilever...";
            });

            // opening cantilever model
            Part = swApp.OpenDoc6("G:\\Cantilever.SLDPRT", 1, 0, "", ref longstatus, ref longwarnings);
            if (Part == null)
            {
                MessageBox.Show("Failed to load cantilever model");
                swApp.ExitApp();
                Dispose();
                Application.Exit();
            }

            swDoc = swApp.IActiveDoc2;
            swDoc.ShowNamedView2("*Isometric", 7);
            swDoc.ViewZoomtofit2();

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            bwStudy.ReportProgress(10);

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Check for Simulation readiness...";
            });

            // ready-check Simulation add-on
            CWAddinCallBack = (CwAddincallback)swApp.GetAddInObject("CosmosWorks.CosmosWorks");
            if (CWAddinCallBack == null)
            {
                MessageBox.Show("Failed to open Simulation");
                Application.Exit();
            }

            // ready-check add-on object
            COSMOSWORKS = CWAddinCallBack.CosmosWorks;
            if (COSMOSWORKS == null)
            {
                MessageBox.Show("Failed to create CosmosWorks object");
                Application.Exit();
            }

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            bwStudy.ReportProgress(14);

            // connecting add-on to the document
            ActDoc = COSMOSWORKS.ActiveDoc;
            if (ActDoc == null)
            {
                MessageBox.Show("Failed to load document");
                Application.Exit();
            }

            bwStudy.ReportProgress(16);

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Setting up an analysis...";
            });

            // creating a frequency analysis
            StudyMngr = ActDoc.StudyManager;
            if (StudyMngr == null)
            {
                MessageBox.Show("Failed to load analysis manager");
                Application.Exit();
            }

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            bwStudy.ReportProgress(18);

            // analysis creation
            Study = StudyMngr.CreateNewStudy3(studyName,
                                              (int)swsAnalysisStudyType_e.swsAnalysisStudyTypeFrequency,
                                              (int)swsMeshType_e.swsMeshTypeSolid, out errCode);
            if (Study == null)
            {
                MessageBox.Show("Failed to create a frequency analysis");
                Application.Exit();
            }

            // analysis settings
            CWOptions = Study.FrequencyStudyOptions;
            // finite element method solver
            // 1 - Automatic Solver Selection, 0 - Direct sparse solver, 2 - FFEPlus, 7 - Intel Direct Sparse
            Study.FrequencyStudyOptions.SolverType      = SolverDict[solverIndex];
            Study.FrequencyStudyOptions.NoOfFrequencies = freqNumber;
            if (CWOptions == null)
            {
                MessageBox.Show("No analysis settings");
            }

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            bwStudy.ReportProgress(20);

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Setting cantilever material...";
            });

            // using silicon as the material (don't know why)
            string matLib = swApp.GetExecutablePath() +
                            @"\lang\english\sldmaterials\solidworks materials.sldmat";

            SolidMgr  = (CWSolidManager)Study.SolidManager;
            SolidComp = SolidMgr.GetComponentAt(0, out errCode);
            if (errCode == 0)
            {
                SolidBody = (CWSolidBody)SolidComp.GetSolidBodyAt(0, out errCode);
                errCode   = (int)SolidBody.SetLibraryMaterial(matLib, "Silicon");
            }
            else
            {
                MessageBox.Show("Failed to apply material");
                Application.Exit();
            }

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Adding restraints...";
            });

            // loading loads and restraints manager
            LBCMgr = Study.LoadsAndRestraintsManager;
            if (LBCMgr == null)
            {
                MessageBox.Show("Failed to load loads and restraints manager");
                Application.Exit();
            }

            bwStudy.ReportProgress(25);

            // face selection followed by applying restraints
            ISelectionMgr selectionMgr = (ISelectionMgr)swDoc.SelectionManager;
            bool          isSelected   = swDoc.Extension.SelectByRay(0.018229940747914952, 0.051969523507693793,
                                                                     0.0020000000000095497, -0.57738154519998097, -0.5772877120855483, -0.57738154519997897,
                                                                     0.00085899699451767535, 2, false, 0, 0);

            if (isSelected)
            {
                object   face_bind = selectionMgr.GetSelectedObject6(1, -1);
                object[] fixedpart = { face_bind };
                CWBind = (CWRestraint)LBCMgr.AddRestraint(0, (fixedpart), null, out errCode);
                if (errCode != 0)
                {
                    MessageBox.Show("Failed to add restraints");
                    Application.Exit();
                }
            }

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            bwStudy.ReportProgress(35);

            swDoc.ClearSelection2(true);

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Creating mesh object...";
            });

            swDoc.ClearSelection2(true);

            // mesh object options
            CWMesh         = ((CWMesh)(Study.Mesh));
            CWMesh.Quality = 1;
            CWMesh.UseJacobianCheckForSolids = 1;
            CWMesh.MesherType                 = 0;
            CWMesh.AutomaticTransition        = 0;
            CWMesh.AutomaticLooping           = 0;
            CWMesh.NumberOfLoops              = 3;
            CWMesh.SaveSettingsWithoutMeshing = 0;
            CWMesh.Unit = 0;

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            bwStudy.ReportProgress(50);

            // create mesh object
            errCode = Study.CreateMesh(0, 13.3821, 0.669103);
            if (errCode != 0)
            {
                MessageBox.Show("Failed to create mesh object");
                Application.Exit();
            }

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Analysing...";
            });

            // start of analysis
            errCode = Study.RunAnalysis();
            if (errCode != 0)
            {
                MessageBox.Show("Failed to start analysis");
                Application.Exit();
            }

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text  = "Analysis has been stopped by user";
                    startBtn.Text          = "Start analysis";
                    solverComboBox.Enabled = true;
                    freqComboBox.Enabled   = true;
                });

                e.Cancel = true;
                return;
            }

            bwStudy.ReportProgress(90);

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Receiving results of analysis...";
            });

            // getting results
            CWResult = (CWResults)Study.Results;
            if (CWResult == null)
            {
                MessageBox.Show("Failed to receive results of analysis");
                return;
            }

            double[] res = new double[10];

            // getting results from the graph
            for (int i = 0; i < freqNumber; i++)
            {
                plot = CWResult.GetPlot("Amplitude" + (i + 1).ToString(), out errCode);
                if (plot == null)
                {
                    MessageBox.Show("Failed to load an information from the graph");
                    return;
                }
                plot.SetComponentUnitAndValueByElem(9, 3, false);
                results = (object[])plot.GetMinMaxResultValues(out errCode);
                res[i]  = Convert.ToDouble(results[3].ToString());
            }

            for (int k = 0; k < freqNumber; k++)
            {
                resGrid.Invoke((MethodInvoker) delegate
                {
                    int n = resGrid.Rows.Add();
                    resGrid.Rows[n].Cells[0].Value = k + 1;
                    resGrid.Rows[n].Cells[1].Value = res[k];
                });
            }

            bwStudy.ReportProgress(100);

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Done";
            });

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                startBtn.Text          = "Review results";
                solverComboBox.Enabled = true;
                freqComboBox.Enabled   = true;
            });
        }
Exemplo n.º 13
0
        private Feature DrawnSketchOnFace(ModelDoc2 swModel, double[] mousePoint, List <Edge> thisFaceEdgeList, Entity swSelFaceEntity, out string sketchName)
        {
            swModel.SketchManager.InsertSketch(true);

            //通过两条相邻边来标注 创建点的位置

            //1。 计算鼠标选中点到面的各边的距离。

            List <FaceEdgeInfos> faceEdgeInfor = new List <FaceEdgeInfos>();

            //Dictionary<Edge, double> pointToEdgeDim = new Dictionary<Edge, double>();

            var selMousePt = (double[])TransformPoint(swModel.IGetActiveSketch2(), mousePoint[0], mousePoint[1], mousePoint[2]);

            foreach (var item in thisFaceEdgeList)
            {
                var tStart = (Vertex)item.GetStartVertex();
                var pstart = (double[])tStart.GetPoint();

                var tEnd = (Vertex)item.GetEndVertex();
                var pend = (double[])tEnd.GetPoint();

                pstart = (double[])TransformPoint(swModel.IGetActiveSketch2(), pstart[0], pstart[1], pstart[2]);
                pend   = (double[])TransformPoint(swModel.IGetActiveSketch2(), pend[0], pend[1], pend[2]);

                var angleOfLine = Math.Atan2((pend[1] - pstart[1]), (pend[0] - pstart[0])) * 180 / Math.PI;

                double tempChuizuX = 0;
                double tempChuizuY = 0;

                //垂足的坐标位置
                var tempchuizu = Geometry2D.GetPerpendicular(selMousePt[0], selMousePt[1], pend[0], pend[1], pstart[0], pstart[1]);

                tempChuizuX = tempchuizu[0];
                tempChuizuY = tempchuizu[1];

                faceEdgeInfor.Add(new FaceEdgeInfos(item, Geometry2D.pointToLine(pstart[0], pstart[1], pend[0], pend[1], selMousePt[0], selMousePt[1]), angleOfLine, Geometry2D.lineSpace(pstart[0], pstart[1], pend[0], pend[1]), tempChuizuX, tempChuizuY));

                //pointToEdgeDim.Add(item, pointToLine(pstart[0], pstart[1], pend[0], pend[1], mousePoint[0], mousePoint[1]));
            }

            //把所有的边按距离排序
            var EdgeInfosOrderByDim = faceEdgeInfor.OrderBy(x => x.dim).ToList();

            //最近的一条边
            var minEdgeObject = EdgeInfosOrderByDim[0];

            //下一条相临的边
            FaceEdgeInfos nextMinEdga = null;

            for (int i = 1; i < EdgeInfosOrderByDim.Count; i++)
            {
                if (Math.Abs(EdgeInfosOrderByDim[i].Angle) != 180 - Math.Abs(minEdgeObject.Angle) && EdgeInfosOrderByDim[i].Angle != minEdgeObject.Angle)
                {
                    nextMinEdga = EdgeInfosOrderByDim[i];
                    break;
                }
            }

            // var eNextEdge = faceEdgeInfoses.Find(x => ((Vertex)x.edge.GetStartVertex()).GetPoint() == ((Vertex)minEdgeObject.GetEndVertex()).GetPoint());

            var minEdge = (Entity)minEdgeObject.edge;

            var nextminEdge = (Entity)nextMinEdga.edge;

            swModel.ClearSelection();

            //MessageBox.Show("done");

            swSelFaceEntity.Select(false);

            // var actSketch = swModel.SketchManager.ActiveSketch;

            ////把鼠标点坐标转换到草图中

            //var selMousePt = (double[])TransformPoint(swModel.IGetActiveSketch2(), mousePoint[0], mousePoint[1], mousePoint[2]);

            swModel.SketchManager.CreateCenterRectangle(selMousePt[0], selMousePt[1], selMousePt[2], selMousePt[0] + 0.03, selMousePt[1] + 0.03, selMousePt[2]);

            swModel.ClearSelection2(true);

            swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, false, 0, null, 0);
            minEdge.Select(true);

            // var thisDim = (DisplayDimension)swModel.AddDimension2(selMousePt[0], selMousePt[1], selMousePt[2]);
            var thisDim = (DisplayDimension)swModel.AddDimension2(minEdgeObject.chuizuPoint_X, minEdgeObject.chuizuPoint_Y, 0);

            thisDim.GetDimension2(0).SystemValue = Math.Round(minEdgeObject.dim * 1000, 0) / 1000;

            //第二个方向尺寸
            swModel.ClearSelection2(true);

            swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, false, 0, null, 0);
            nextminEdge.Select(true);

            //var nextthisDim = (DisplayDimension)swModel.AddDimension2(selMousePt[0], selMousePt[1], selMousePt[2]);
            var nextthisDim = (DisplayDimension)swModel.AddDimension2(nextMinEdga.chuizuPoint_X, nextMinEdga.chuizuPoint_Y, 0);

            nextthisDim.GetDimension2(0).SystemValue = Math.Round(nextMinEdga.dim * 1000, 0) / 1000;

            string featName = null;
            string featType = null;

            var skFeature = (Feature)swModel.IGetActiveSketch2();

            featName   = skFeature.GetNameForSelection(out featType);
            sketchName = featName;

            swModel.SketchManager.InsertSketch(true);

            swModel.Extension.SelectByID2(sketchName, "SKETCH", 0, 0, 0, false, 1, null, 0);

            var boolstatus = swModel.InsertPlanarRefSurface();

            ISelectionMgr swSelMgr = (ISelectionMgr)swModel.SelectionManager;

            skFeature = (Feature)swSelMgr.GetSelectedObject6(1, 0);// swModel.FeatureByPositionReverse(0);

            return(skFeature);
        }
Exemplo n.º 14
0
        private Boolean AddMacroFeature()
        {
            IModelDoc2      moddoc;
            IFeatureManager FeatMgr;
            IFeature        MacroFeature;
            Object          paramNames;
            Object          paramTypes;
            Object          paramValues;

            string[] TparamNames  = new string[3];
            int[]    TparamTypes  = new int[3]; //Use int for 64 bit compatibility
            string[] TparamValues = new string[3];
            IBody2   editBody;
            int      opts;

            moddoc  = (IModelDoc2)iSwApp.ActiveDoc;
            FeatMgr = (IFeatureManager)moddoc.FeatureManager;
            ISelectionMgr swSelMgr = (ISelectionMgr)moddoc.SelectionManager;

            if (swSelMgr.GetSelectedObjectCount() != 1)
            {
                iSwApp.SendMsgToUser("Please select one face or plane");

                return(false);
            }

            var selFace = swSelMgr.GetSelectedObject6(1, 1);

            Feature[] swFeature = AddTMPBasePlaneFromSelectFace();

            //Include only data that won't be available from geometry
            TparamNames[0] = "Size";

            TparamTypes[0] = (int)swMacroFeatureParamType_e.swMacroFeatureParamTypeDouble;

            TparamValues[0] = newFeaturePmPage.SizeValue;
            //TparamNames[0] = "Width";
            //TparamNames[1] = "Offset";
            //TparamNames[2] = "Depth";

            //TparamTypes[0] = (int)swMacroFeatureParamType_e.swMacroFeatureParamTypeDouble;
            //TparamTypes[1] = (int)swMacroFeatureParamType_e.swMacroFeatureParamTypeDouble;
            //TparamTypes[2] = (int)swMacroFeatureParamType_e.swMacroFeatureParamTypeDouble;

            ////Hard code the parameters for test,
            ////but in practice get this from Property Manager Page
            //TparamValues[0] = "0.01"; //Width
            //TparamValues[1] = "0.005"; //Offset
            //TparamValues[2] = "0.006"; //Depth

            paramNames  = TparamNames;
            paramTypes  = TparamTypes;
            paramValues = TparamValues;

            string[] icos = new string[9];
            icos[0] = @"FeatureIcon.bmp";
            icos[1] = @"FeatureIcon.bmp";
            icos[2] = @"FeatureIcon.bmp";
            icos[3] = @"FeatureIcon.bmp";
            icos[4] = @"FeatureIcon.bmp";
            icos[5] = @"FeatureIcon.bmp";
            icos[6] = @"FeatureIcon.bmp";
            icos[7] = @"FeatureIcon.bmp";
            icos[8] = @"FeatureIcon.bmp";

            editBody = null;

            opts = 0;

            MacroFeature = FeatMgr.InsertMacroFeature3("New-Feature", "PaineTool.NewFeature.NewFeatureHandler", null, (paramNames), (paramTypes), (paramValues), null, null, editBody, icos, opts);

            //var featureDif = (MacroFeatureData)MacroFeature.GetDefinition();

            // featureDif.GetSelectedObjects(Filter);

            //var selObj = new DispatchWrapper[] { selFace }; ;
            //var selObjMark = new int[] { 0 };
            //var views = new IView[] { null };

            //featureDif.SetSelections2(selObj, selObjMark, views);

            //featureDif.SetSelections(selFace, 1);

            foreach (var item in swFeature)
            {
                // MessageBox.Show(item.Name);

                MacroFeature.MakeSubFeature(item);
            }

            // featureDif.ReleaseSelectionAccess();

            TparamNames  = null;
            TparamTypes  = null;
            TparamValues = null;

            return(true);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Sets the source interops
 /// </summary>
 /// <param name="doc"></param>
 public SolidworksDocument(IModelDoc2 doc)
 {
     _doc          = doc;
     _extension    = doc.Extension;
     _selectionMgr = doc.SelectionManager;
 }
 public static IReadOnlyList <object> GetAllSelectedObjects(this ISelectionMgr selMgr)
 {
     return(selMgr.GetSelectedObjects((t, m) => true));
 }
 /// <summary>
 /// 通过委托来创建一个Callout--单实例,不支持使用此方法创建两个
 /// </summary>
 /// <param name="seleMgr"></param>
 /// <param name="RowsNum"></param>
 /// <param name="func"></param>
 /// <returns></returns>
 public static Callout CreateCallOut(this ISelectionMgr seleMgr, int RowsNum, Func <ICallout, int, string, bool> func)
 {
     return(seleMgr.CreateCallout2(RowsNum, SwCalloutHandlerWrapperHelper.CreateWrapper(func)));
 }
Exemplo n.º 18
0
        // another thread work
        void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            // banning empty fields
            if (string.IsNullOrWhiteSpace(strBox.Text))
            {
                MessageBox.Show("Enter force value", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate {
                processNameLabel.Text = "Launching SolidWorks...";
            });

            // check for manual cancelling of analysis
            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            // opening SW 2017
            Guid   Guid1     = new Guid("6B36082E-677B-49E8-BCB2-76698EBD2906");
            object processSW = System.Activator.CreateInstance(System.Type.GetTypeFromCLSID(Guid1));

            swApp         = (SldWorks)processSW;
            swApp.Visible = true;

            processNameLabel.Invoke((MethodInvoker) delegate {
                processNameLabel.Text = "Preparing Simulation...";
            });

            CosmosWorks                 COSMOSWORKS     = default(CosmosWorks);
            CwAddincallback             CWAddinCallBack = default(CwAddincallback);
            CWModelDoc                  ActDoc          = default(CWModelDoc);
            CWStudyManager              StudyMngr       = default(CWStudyManager);
            CWStudy                     Study           = default(CWStudy);
            CWStaticStudyOptions        CWOptions       = default(CWStaticStudyOptions);
            CWLoadsAndRestraintsManager LBCMgr          = default(CWLoadsAndRestraintsManager);
            CWRestraint                 CWBind          = default(CWRestraint);
            CWForce                     CWStr           = default(CWForce);
            CWMesh    CWMesh   = default(CWMesh);
            CWResults CWResult = default(CWResults);
            CWPlot    plot     = default(CWPlot);

            ModelDoc2 Part         = default(ModelDoc2);
            ModelDoc2 swDoc        = null;
            int       longstatus   = 0;
            int       longwarnings = 0;
            int       errCode      = 0;

            object[] results = null;

            // analysis name
            string study_name = studyNameBox.Text;

            if (string.IsNullOrWhiteSpace(study_name))
            {
                study_name = "Static_beam";
            }

            bwStudy.ReportProgress(5);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate {
                processNameLabel.Text = "Creating beam model...";
            });

            // opening SLDPRT file containing beam model
            Part = swApp.OpenDoc6("C:\\Beam.SLDPRT", 1, 0, "", ref longstatus, ref longwarnings);
            if (Part == null)
            {
                MessageBox.Show("Failed to open model");
                Application.Exit();
            }

            string path_to_cosworks_dll = swApp.GetExecutablePath() + @"\Simulation\cosworks.dll";

            longstatus = swApp.LoadAddIn(path_to_cosworks_dll);

            // isometric view
            swDoc = swApp.IActiveDoc2;
            swDoc.ShowNamedView2("*Isometric", 7);
            swDoc.ViewZoomtofit2();

            bwStudy.ReportProgress(10);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Starting Simulation...";
            });

            // ready-check Simulation add-on
            CWAddinCallBack = (CwAddincallback)swApp.GetAddInObject("CosmosWorks.CosmosWorks");
            if (CWAddinCallBack == null)
            {
                MessageBox.Show("Failed to start Simulation");
                Application.Exit();
            }

            bwStudy.ReportProgress(12);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            // ready-check add-on object
            COSMOSWORKS = CWAddinCallBack.CosmosWorks;
            if (COSMOSWORKS == null)
            {
                MessageBox.Show("Failed to create CosmosWorks object");
                Application.Exit();
            }

            bwStudy.ReportProgress(14);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            // connecting add-on to document
            ActDoc = COSMOSWORKS.ActiveDoc;
            if (ActDoc == null)
            {
                MessageBox.Show("Failed to connect to document");
                Application.Exit();
            }

            bwStudy.ReportProgress(16);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Creating analysis...";
            });

            // creating static analysis
            StudyMngr = ActDoc.StudyManager;
            if (StudyMngr == null)
            {
                MessageBox.Show("Failed to start analysis manager");
                Application.Exit();
            }

            bwStudy.ReportProgress(18);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            Study = StudyMngr.CreateNewStudy3(study_name, (int)swsAnalysisStudyType_e.swsAnalysisStudyTypeStatic, (int)swsMeshType_e.swsMeshTypeSolid, out errCode);
            if (Study == null)
            {
                MessageBox.Show("Failed to create static analysis");
                Application.Exit();
            }

            bwStudy.ReportProgress(20);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Adding attachment object...";
            });

            // loading indicator manager
            LBCMgr = Study.LoadsAndRestraintsManager;
            if (LBCMgr == null)
            {
                MessageBox.Show("Failed to load indicator manager");
                Application.Exit();
            }

            bwStudy.ReportProgress(25);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            // selecting face for attachment and adding it to indicator manager
            ISelectionMgr selectionMgr = (ISelectionMgr)swDoc.SelectionManager;
            bool          isSelected   = swDoc.Extension.SelectByRay(-0.023870052576342005, 0.064003232713616853, 0, -0.57738154519998108, -0.57728771208554841, -0.57738154519997897, 0.0037366684901689287, 2, true, 0, 0);

            if (isSelected)
            {
                object   face_bind = selectionMgr.GetSelectedObject6(1, -1);
                object[] fixedpart = { face_bind };
                CWBind = (CWRestraint)LBCMgr.AddRestraint(0, (fixedpart), null, out errCode);
                if (errCode != 0)
                {
                    MessageBox.Show("Failed to add attachment object");
                    Application.Exit();
                }
            }

            bwStudy.ReportProgress(35);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Adding force indicator...";
            });

            swDoc.ClearSelection2(true);

            isSelected = swDoc.Extension.SelectByRay(0.00094849719312151137, 0.029999999999915872, 0.97601905600942018, -0.57738154519998108, -0.57728771208554841, -0.57738154519997897, 0.0037366684901689287, 2, true, 0, 0);
            if (isSelected)
            {
                object   face_force      = selectionMgr.GetSelectedObject6(1, -1);
                object[] fixedpart       = { face_force };
                object[] DistanceValues  = { };
                object[] ForceValues     = { };
                object[] ComponentValues = { };
                CWStr = (CWForce)LBCMgr.AddForce3(1, 0, -1, 0, 0, 0, DistanceValues, ForceValues, false, false, 0, 0, 0, Convert.ToInt32(strBox.Text), ComponentValues, false, false, (fixedpart), null, false, out errCode);
                if (errCode != 0)
                {
                    MessageBox.Show("Failed to add force indicator");
                    Application.Exit();
                }
                CWStr.ForceBeginEdit();
                CWStr.Unit = 2;
                CWStr.ForceEndEdit();
            }

            bwStudy.ReportProgress(50);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Creating mesh object...";
            });

            swDoc.ClearSelection2(true);

            // mesh object parameters
            CWMesh         = ((CWMesh)(Study.Mesh));
            CWMesh.Quality = 1;
            CWMesh.UseJacobianCheckForSolids = 1;
            CWMesh.MesherType                 = 0;
            CWMesh.AutomaticTransition        = 0;
            CWMesh.AutomaticLooping           = 0;
            CWMesh.NumberOfLoops              = 3;
            CWMesh.SaveSettingsWithoutMeshing = 0;
            CWMesh.Unit = 0;

            bwStudy.ReportProgress(70);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            // creating mesh object
            errCode = Study.CreateMesh(0, 13.3821, 0.669103);
            if (errCode != 0)
            {
                MessageBox.Show("Failed to create mesh object");
                Application.Exit();
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Starting analysis...";
            });

            // starting analysis
            errCode = Study.RunAnalysis();
            if (errCode != 0)
            {
                MessageBox.Show("Failed to start analysis");
                Application.Exit();
            }

            bwStudy.ReportProgress(90);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Receiving analysis results...";
            });

            // obtaining results
            CWResult = (CWResults)Study.Results;
            if (CWResult == null)
            {
                MessageBox.Show("Failed to receive results");
                return;
            }

            // stress graph results
            plot = CWResult.GetPlot("Stress1", out errCode);
            if (plot == null)
            {
                MessageBox.Show("Failed to receive stress results");
                return;
            }
            plot.SetComponentUnitAndValueByElem(9, 3, false);
            results = (object[])plot.GetMinMaxResultValues(out errCode);

            max_tens = Convert.ToDouble(results[3].ToString());
            min_tens = Convert.ToDouble(results[1].ToString());

            bwStudy.ReportProgress(93);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            // displacement graph results
            plot = CWResult.GetPlot("Displacement1", out errCode);
            if (plot == null)
            {
                MessageBox.Show("Failed to receive displacement results");
                return;
            }
            plot.SetComponentUnitAndValueByElem(3, 0, false);
            results = (object[])plot.GetMinMaxResultValues(out errCode);

            max_move = Convert.ToDouble(results[3].ToString());
            min_move = Convert.ToDouble(results[1].ToString());

            bwStudy.ReportProgress(96);

            if (bwStudy.CancellationPending == true)
            {
                processNameLabel.Invoke((MethodInvoker) delegate
                {
                    processNameLabel.Text = "Analysis has been cancelled";
                });

                e.Cancel = true;
                return;
            }

            // strain graph results
            plot = CWResult.GetPlot("Strain1", out errCode);
            if (plot == null)
            {
                MessageBox.Show("Failed to receive strain results");
                return;
            }
            plot.SetComponentUnitAndValueByElem(6, 3, false);
            results = (object[])plot.GetMinMaxResultValues(out errCode);

            bwStudy.ReportProgress(99);

            max_deform = Convert.ToDouble(results[3].ToString());
            min_deform = Convert.ToDouble(results[1].ToString());

            maxTensBox.Invoke((MethodInvoker) delegate
            {
                maxTensBox.Text = max_tens.ToString();
            });

            minTensBox.Invoke((MethodInvoker) delegate
            {
                minTensBox.Text = min_tens.ToString();
            });

            maxMoveBox.Invoke((MethodInvoker) delegate
            {
                maxMoveBox.Text = max_move.ToString();
            });

            minMoveBox.Invoke((MethodInvoker) delegate
            {
                minMoveBox.Text = min_move.ToString();
            });

            maxDeformBox.Invoke((MethodInvoker) delegate
            {
                maxDeformBox.Text = max_deform.ToString();
            });

            minDeformBox.Invoke((MethodInvoker) delegate
            {
                minDeformBox.Text = min_deform.ToString();
            });

            bwStudy.ReportProgress(100);

            processNameLabel.Invoke((MethodInvoker) delegate
            {
                processNameLabel.Text = "Done";
            });
        }
        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);
            }
        }
Exemplo n.º 20
0
 internal SwSelObjectEnumerator(SwDocument doc, ISelectionMgr selMgr)
 {
     m_CurSelIndex = 0;
     m_Doc         = doc;
     m_SelMgr      = selMgr;
 }
Exemplo n.º 21
0
 public static IDisposable DeselectAllUndoable(this ISelectionMgr selMgr)
 {
     selMgr.SuspendSelectionList();
     return(Disposable.Create(selMgr.ResumeSelectionList));
 }
Exemplo n.º 22
0
 public ISelectionMgrObject(ISelectionMgr ISelectionMgrinstance)
 {
     ISelectionMgrInstance = ISelectionMgrinstance;
 }