public void AttachEventsToAllDocuments()
        {
            ModelDoc2 modDoc = (ModelDoc2)SwApp.GetFirstDocument();

            while (modDoc != null)
            {
                if (!OpenDocs.Contains(modDoc))
                {
                    AttachModelDocEventHandler(modDoc);
                }
                else if (OpenDocs.Contains(modDoc))
                {
                    DocumentEventHandler docHandler = (DocumentEventHandler)OpenDocs[modDoc];
                    if (docHandler != null)
                    {
                        bool connected = docHandler.ConnectModelViews();
                        if (!connected)
                        {
                            logger.Warn("Failed to connect to model views");
                        }
                    }
                }

                modDoc = (ModelDoc2)modDoc.GetNext();
            }
        }
        public void DoWithOpenDocShouldCleanup()
        {
            var opened = 0;
            var closed = 0;

            using (SwApp.DoWithOpenDoc(doc =>
            {
                opened++;
                return(Disposable.Create(() => closed++));
            }))
            {
                opened.Should().Be(0);
                closed.Should().Be(0);

                var doc = CreatePartDoc();

                opened.Should().Be(1);
                closed.Should().Be(0);

                var doc2 = CreatePartDoc();

                opened.Should().Be(2);
                closed.Should().Be(0);

                SwApp.CloseDoc(doc2.GetTitle());

                opened.Should().Be(2);
                closed.Should().Be(1);

                SwApp.CloseDoc(doc.GetTitle());

                opened.Should().Be(2);
                closed.Should().Be(2);
            }
        }
        public bool ConnectToSW(object ThisSW, int cookie)
        {
            logger.Info("Attempting to connect to SW");
            SwApp      = (ISldWorks)ThisSW;
            add_in_id_ = cookie;

            //Setup callbacks
            logger.Info("Setting up callbacks");
            SwApp.SetAddinCallbackInfo(0, this, add_in_id_);

            #region Setup the Command Manager
            logger.Info("Setting up command manager");
            CmdMgr = SwApp.GetCommandManager(cookie);

            logger.Info("Adding command manager");
            AddCommandMgr();

            #endregion Setup the Command Manager

            #region Setup the Event Handlers
            logger.Info("Adding event handlers");
            SwEventPtr = (SldWorks)SwApp;
            OpenDocs   = new Hashtable();
            AttachEventHandlers();

            #endregion Setup the Event Handlers

            logger.Info("Connecting plugin to SolidWorks");
            return(true);
        }
        public bool ConnectToSW(object ThisSW, int cookie)
        {
            SwApp   = (ISldWorks)ThisSW;
            addinID = cookie;

            //Setup callbacks
            SwApp.SetAddinCallbackInfo(0, this, addinID);

            #region Setup the Command Manager

            CmdMgr = SwApp.GetCommandManager(cookie);
            AddCommandMgr();

            #endregion Setup the Command Manager

            #region Setup the Event Handlers

            SwEventPtr = (SldWorks)SwApp;
            OpenDocs   = new Hashtable();
            AttachEventHandlers();

            #endregion Setup the Event Handlers

            logger.Info("Connecting plugin to SolidWorks");
            return(true);
        }
 public void RemoveCommandMgr()
 {
     SwApp.RemoveMenu((int)swDocumentTypes_e.swDocASSEMBLY, "Export as URDF@&File", "");
     logger.Info("Removing assembly export from file menu");
     SwApp.RemoveMenu((int)swDocumentTypes_e.swDocPART, "Export as URDF@&File", "");
     logger.Info("Removing part export from file menu");
 }
        public void AddCommandMgr()
        {
            // Do not use AddMenuItem5 here despite the obselete warning, AddMenuItem5 doesn't work
            string[] images =
            {
                "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_20x20.png",
                "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_32x32.png",
                "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_40x40.png",
                "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_64x64.png",
                "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_96x96.png",
                "C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_128x128.png",
            };
            int ret = SwApp.AddMenuItem5((int)swDocumentTypes_e.swDocASSEMBLY, add_in_id_, "Export as URDF@&Tools",
                                         -1, "AssemblyURDFExporter", "", "Export assembly as URDF file", images);

            if (ret < 0)
            {
                logger.Error("Failure to add menu item 'Export as URDF' to menu 'Tools'");
                return;
            }
            logger.Info("Adding Assembly export to file menu");
            ret = SwApp.AddMenuItem5((int)swDocumentTypes_e.swDocPART, add_in_id_, "Export as URDF@&Tools",
                                     -1, "PartURDFExporter", "", "Export part as URDF file", images);
            if (ret < 0)
            {
                logger.Error("Failure to add menu item 'Export as URDF' to menu 'Tools'");
                return;
            }

            logger.Info("Adding Part export to file menu");
        }
Пример #7
0
        /// <summary>
        /// As yet unused warning.
        /// </summary>
        private void AskWrite()
        {
            string q = "Write unwritten properties?";
            swMessageBoxResult_e r = (swMessageBoxResult_e)SwApp.SendMsgToUser2(q,
                                                                                (int)swMessageBoxIcon_e.swMbQuestion, (int)swMessageBoxBtn_e.swMbYesNo);

            switch (r)
            {
            case swMessageBoxResult_e.swMbHitAbort:
                break;

            case swMessageBoxResult_e.swMbHitCancel:
                break;

            case swMessageBoxResult_e.swMbHitIgnore:
                break;

            case swMessageBoxResult_e.swMbHitNo:
                break;

            case swMessageBoxResult_e.swMbHitOk:
                break;

            case swMessageBoxResult_e.swMbHitRetry:
                break;

            case swMessageBoxResult_e.swMbHitYes:
                Write();
                break;

            default:
                break;
            }
        }
        public void TestSelectComponentsLink(string modelName)
        {
            ModelDoc2   doc      = OpenSWDocument(modelName);
            AssemblyDoc assyDoc  = (AssemblyDoc)doc;
            LinkNode    baseNode = ConfigurationSerialization.LoadBaseNodeFromModel(doc, out bool abortProcess);

            Assert.False(abortProcess);

            Link baseLink = baseNode.RebuildLink();
            List <Component2> componentsToSelect = new List <Component2>();

            AddLinkComponents(baseLink, componentsToSelect);
            HashSet <string> componentsToSelectNames =
                new HashSet <string>(componentsToSelect.Select(component => component.Name2));

            CommonSwOperations.SelectComponents(doc, baseLink, true);
            SelectionMgr selManager  = doc.SelectionManager;
            int          numSelected = selManager.GetSelectedObjectCount2(-1);

            Assert.Equal(componentsToSelect.Count, numSelected);

            for (int i = 0; i < selManager.GetSelectedObjectCount2(-1); i++)
            {
                Component2 comp = selManager.GetSelectedObjectsComponent4(i, -1);
                Assert.Contains(comp.Name2, componentsToSelectNames);
            }

            SwApp.CloseAllDocuments(true);
        }
        public void TestWriteRobotToCSV(string modelName, int expNumLines)
        {
            ModelDoc2 doc      = OpenSWDocument(modelName);
            LinkNode  baseNode = Serialization.LoadBaseNodeFromModel(SwApp, doc, out bool abortProcess);

            Assert.False(abortProcess);
            Link  baseLink = baseNode.GetLink();
            Robot robot    = new Robot();

            robot.SetBaseLink(baseLink);

            string tempFile = Path.GetTempFileName();

            try
            {
                ImportExport.WriteRobotToCSV(robot, tempFile);
                Assert.True(File.Exists(tempFile));

                string[] text = File.ReadAllLines(tempFile);
                Assert.Equal(expNumLines, text.Length);
            }
            catch (Exception e)
            {
                Assert.True(false, "Failed to write robot to CSV " + e.Message);
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                    Assert.True(SwApp.CloseAllDocuments(true));
                }
            }
        }
Пример #10
0
        public void didBuildModel()
        {
            SwApp.NewPart();
            _swModel = SwApp.IActiveDoc2;
            _swPart  = (PartDoc)(_swModel);

            _swModel.Extension.SelectByID2("Top", "PLANE", 0, 0, 0, false, 0, null, 0);
            _swModel.SketchManager.InsertSketch(true);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.CreateCornerRectangle(0, 0, 0, Length, Width, 0);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.InsertSketch(true);

            _swModel.FeatureManager.FeatureExtrusion2(true, false, false, 0, 0, Height, 0.01, false, false, false, false, 1.74532925199433E-02, 1.74532925199433E-02, false, false, false, false, true, true, true, 0, 0, false);

            _swModel.Extension.SelectByID2("", "FACE", Length / 2, Height, -Width / 2, false, 0, null, 0);
            _swModel.ShowNamedView2("*Top", 5);

            _swModel.ViewZoomTo2(-1.40224455089843E-02, 7.79877043000974E-02, 0, 0.090572328390715, -1.30337019942975E-02, 0);

            _swModel.SketchManager.CreateCircle(0.004, Width - 0.004, 0, 0.004, Width - 0.004 + 0.00135, 0);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.CreateCircle(0.004, 0.004, 0, 0.004, 0.00535, 0);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.CreateCircle(Length - 0.004, Width - 0.004, 0, Length - 0.004, Width - 0.004 + 0.00135, 0);
            _swModel.ClearSelection2(true);

            _swModel.SketchManager.CreateCircle(Length - 0.004, 0.004, 0, Length - 0.004, 0.00535, 0);
            _swModel.ClearSelection2(true);

            _swModel.ShowNamedView2("*Isometry", 7);

            _swModel.Extension.SelectByID2("Arc1@", "EXTSKETCHSEGMENT", 5.96034675525732E-03, 6.63356185593879E-02, 0, false, 0, null, 0);
            _swModel.FeatureManager.FeatureCut3(true, false, false, 1, 0, 0.005, 0.005, false, false, false, false, 1.74532925199433E-02, 1.74532925199433E-02, false, false, false, false, false, true, true, true, true, false, 0, 0, false);

            _swModel.ViewZoomTo2(-1.30039690871637E-02, 3.75387366394858E-02, 1.58777579102132E-02, 0.142076690355558, -0.052121832944159, 1.58777579102138E-02);
            _swModel.ShowNamedView2("*Left", 3);
            _swModel.ViewZoomTo2(-0.083498837770881115, 0.014433467968860341, -0.060000000000000081, 0.0096740082936823124, -0.016165167848730275, -0.059999999999999866);
            _swModel.Extension.SelectByID2("", "EDGE", 0, Height / 2, 0, true, 0, null, 0);
            _swModel.Extension.SelectByID2("", "EDGE", 0, Height / 2, -Width, true, 0, null, 0);
            _swModel.ShowNamedView2("*Righr", 4);
            _swModel.ViewZoomTo2(-0.013345844591793166, 0.018717276983323025, 0.059999999999999894, 0.080438974189122076, -0.017083126923257995, 0.060000000000000143);
            _swModel.Extension.SelectByID2("", "EDGE", Length, Height / 2, 0, true, 0, null, 0);
            _swModel.Extension.SelectByID2("", "EDGE", Length, Height / 2, -Width, true, 0, null, 0);
            _swModel.ShowNamedView2("*Isometry", 7);
            _swModel.FeatureManager.InsertFeatureChamfer(4, 1, 0.0027, 0.78539816339745, 0, 0, 0, 0);


            _swModel.Extension.SelectByID2("Body-Feature1", "BODYFEATURE", 0, 0, 0, false, 0, null, 0);
            _swModel.Extension.SelectByID2("Unknown", "BROWSERITEM", 0, 0, 0, false, 0, null, 0);
            _swModel.ClearSelection2(true);
            _swPart.SetMaterialPropertyName2("По умолчанию", @"C:/ProgramData/SolidWorks/SolidWorks 2012/Sustainability/Sustainability Extras.sldmat", "Плата системы питания");
            _swModel.ClearSelection2(true);

            _swModel.SaveAs3(@"C:\Certificate\plata.SLDPRT", 0, 2);
        }
Пример #11
0
        void addUI()
        {
            string hint        = "Uploads the model to Sketchfab";
            string callback    = "PublishCmd_Callback";
            string enable_mthd = "Publish_Enable";
            int    position    = 16; // Before 'Publish to 3DVia.com...'

            int[] showInDocumentTypes = new int[2] {
                (int)swDocumentTypes_e.swDocPART, (int)swDocumentTypes_e.swDocASSEMBLY
            };

            string file_path = bitmapHandler.CreateFileFromResourceBitmap("SketchfabExporterforSW.sketchfab.bmp", this.GetType().Assembly);


            foreach (var type in showInDocumentTypes)
            {
                SwApp.AddMenuItem4(
                    type,
                    Cookie,
                    PublishMenuTitle,
                    position,
                    callback,
                    enable_mthd,
                    hint,
                    file_path);
            }
        }
        public void TestSelectComponentsList(string modelName)
        {
            ModelDoc2   doc      = OpenSWDocument(modelName);
            AssemblyDoc assyDoc  = (AssemblyDoc)doc;
            LinkNode    baseNode = Serialization.LoadBaseNodeFromModel(SwApp, doc, out bool abortProcess);

            Assert.False(abortProcess);

            Link baseLink = baseNode.GetLink();
            List <Component2> componentsToSelect      = baseLink.SWComponents;
            HashSet <string>  componentsToSelectNames =
                new HashSet <string>(componentsToSelect.Select(component => component.Name2));

            Common.SelectComponents(doc, componentsToSelect, true);
            SelectionMgr selManager = doc.SelectionManager;

            // -1 is the Mark, set to negative one if it's not being used.
            int numSelected = selManager.GetSelectedObjectCount2(-1);

            Assert.Equal(componentsToSelect.Count, numSelected);

            for (int i = 0; i < selManager.GetSelectedObjectCount2(-1); i++)
            {
                // -1 is the Mark, set to negative one if it's not being used.
                Component2 comp = selManager.GetSelectedObjectsComponent4(i, -1);
                Assert.Contains(comp.Name2, componentsToSelectNames);
            }

            SwApp.CloseAllDocuments(true);
        }
Пример #13
0
        public void TestLocalizeAxis(string modelName, double[] axis, string coordSys, double[] expected)
        {
            ModelDoc2    doc    = OpenSWDocument(modelName);
            ExportHelper helper = new ExportHelper(SwApp);

            Assert.Equal(expected, helper.LocalizeAxis(axis, coordSys));
            Assert.True(SwApp.CloseAllDocuments(true));
        }
Пример #14
0
        public void TestGetRefAxes(string modelName, string[] expected)
        {
            ModelDoc2    doc    = OpenSWDocument(modelName);
            ExportHelper helper = new ExportHelper(SwApp);

            Assert.Equal(new List <string>(expected), helper.GetRefAxes());
            Assert.True(SwApp.CloseAllDocuments(true));
        }
        // TODO(SIMINT-164) pm.Show() crashes with drag drop
        //[Theory]
        //[InlineData("3_DOF_ARM")]
        public void TestPropertyManagerOpens(string modelName)
        {
            OpenSWDocument(modelName);
            SwAddin addin = new SwAddin();

            addin.ConnectToSW(SwApp, 0);
            addin.SetupAssemblyExporter();
            SwApp.CloseAllDocuments(true);
        }
Пример #16
0
 /// <summary>
 /// If this ever comes up, I suppose it's because the wrong kind of doc is open.
 /// </summary>
 private void SetupOther()
 {
     // Blow out any existing controls, and dump events.
     ClearControls(this);
     SwApp.SendMsgToUser2(
         Properties.Resources.MustOpenDocument,
         (int)swMessageBoxIcon_e.swMbInformation,
         (int)swMessageBoxBtn_e.swMbOk);
 }
        public void TestFindHiddenComponens(string modelName, int expected)
        {
            ModelDoc2   doc     = OpenSWDocument(modelName);
            AssemblyDoc assyDoc = (AssemblyDoc)doc;

            Assert.Equal(expected, Common.FindHiddenComponents(assyDoc.GetComponents(false)).Count);

            SwApp.CloseAllDocuments(true);
        }
Пример #18
0
        private void Initialize()
        {
            IFeature swFeature = ((IModelDoc2)swAssembly).FirstFeature();

            while (swFeature != null)
            {
                /*Console.WriteLine("+++++ " + swFeature.Name + " - " + swFeature.GetID() + " - " + swFeature.IsSuppressed2(
                 *  (int)swInConfigurationOpts_e.swThisConfiguration, null)[0]
                 + "\n \t ++ Created: " + swFeature.DateCreated + "\n \t ++ Modified: " + swFeature.DateModified
                 + "\n \t ++ CreatedBy: " + swFeature.CreatedBy);
                 */
                if (!swFeature.IsSuppressed2((int)swInConfigurationOpts_e.swThisConfiguration, null)[0])
                {
                    var swEntity          = (IEntity)swFeature;
                    var swEntityType      = (swSelectType_e)swEntity.GetType();
                    var featureTypeName   = swFeature.GetTypeName2();
                    var featureDefinition = swFeature.GetDefinition();
                    var specificFeature   = swFeature.GetSpecificFeature2();

                    if (swSelectType_e.swSelBODYFEATURES == swEntityType)
                    {
                        bodyFeatures.Add(new BodyFeature(swFeature)); // swFeature.GetDefinition()
                                                                      // Console.WriteLine("++++ " + swFeature.GetTypeName2() + " - " + swFeature.Name + " - " + (swFeature.GetDefinition() is IExtrudeFeatureData2));
                    }

                    if (swSelectType_e.swSelMATEGROUPS == swEntityType)
                    {
                        //Get first mate, which is a subfeature
                        IFeature swMateFeature = (Feature)swFeature.GetFirstSubFeature();
                        while (null != swMateFeature)
                        {
                            // Console.WriteLine(swMateFeature.IsSuppressed2(1, null)[0]);
                            mates.Add(new Mate(swMateFeature));
                            swMateFeature = swMateFeature.GetNextSubFeature();
                        }
                    }

                    if (swSelectType_e.swSelCOMPONENTS == swEntityType)
                    {
                        var swModelDoc = ((IComponent2)swFeature.GetSpecificFeature2()).GetModelDoc2();
                        // Console.WriteLine(((IComponent2)swFeature.GetSpecificFeature2()).IsSuppressed());

                        if (swModelDoc is IAssemblyDoc)
                        {
                            SwApp.ActivateDocument(swModelDoc);
                            subAssemblies.Add(new Assembly((IAssemblyDoc)swModelDoc, swFeature));
                        }

                        if (swModelDoc is IPartDoc)
                        {
                            parts.Add(new Part((IPartDoc)swModelDoc, swFeature));
                        }
                    }
                }
                swFeature = swFeature.GetNextFeature();
            }
        }
 public void AddCommandMgr()
 {
     SwApp.AddMenuItem3((int)swDocumentTypes_e.swDocASSEMBLY, addinID, "Export as URDF@&File",
                        10, "AssemblyURDFExporter", "", "Export assembly as URDF file", "");
     logger.Info("Adding Assembly export to file menu");
     SwApp.AddMenuItem3((int)swDocumentTypes_e.swDocPART, addinID, "Export as URDF@&File",
                        10, "PartURDFExporter", "", "Export part as URDF file", "");
     logger.Info("Adding Part export to file menu");
 }
Пример #20
0
        public void didLoadPcb()
        {
            _swModel = SwApp.NewDocument(@"C:\ProgramData\SolidWorks\SolidWorks 2012\templates\gost-assy.asmdot", 0, 0, 0);
            SwApp.ActivateDoc2("Assembly1", false, _longstatus);
            _swModel = SwApp.ActiveDoc;

            SwAssy = (AssemblyDoc)_swModel;
            SwApp.OpenDoc6(@"C:\Certificate\plata.SLDPRT", 1, 0, "", _longstatus, _longwarnings);
            SwAssy.AddComponent(@"C:\Certificate\plata.SLDPRT", Length / 2, Height / 2, -Width / 2);
        }
        public void TestShowAllComponents(string modelName)
        {
            ModelDoc2   doc     = OpenSWDocument(modelName);
            AssemblyDoc assyDoc = (AssemblyDoc)doc;

            Common.ShowAllComponents(doc, new List <string>());
            Assert.Equal(0, Common.FindHiddenComponents(assyDoc.GetComponents(false)).Count);

            SwApp.CloseAllDocuments(true);
        }
        public void TestGetRPYMathTransform(double[] matrixData, double[] expected)
        {
            MathUtility   util      = SwApp.GetMathUtility();
            MathTransform transform = util.CreateTransform((object)matrixData);

            double[] result = MathOps.GetRPY(transform);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], result[i], 10);
            }
        }
Пример #23
0
    private void create_dwg(FileInfo p)
    {
        int    dt          = (int)SolidWorks.Interop.swconst.swDocumentTypes_e.swDocDRAWING;
        int    odo         = (int)SolidWorks.Interop.swconst.swOpenDocOptions_e.swOpenDocOptions_Silent;
        int    err         = 0;
        int    warn        = 0;
        string newName     = p.Name.Replace(".SLDDRW", targetExt);
        string tmpFile     = string.Format(@"{0}\{1}", Path.GetTempPath(), newName);
        string fileName    = p.FullName.Replace(".SLDDRW", targetExt);
        int    saveVersion = (int)swSaveAsVersion_e.swSaveAsCurrentVersion;
        int    saveOptions = (int)swSaveAsOptions_e.swSaveAsOptions_Silent;
        bool   success;

        OnAppend(new AppendEventArgs(string.Format("Creating {0}...",
                                                   p.Name.Replace(@".SLDDRW", targetExt))));
        SwApp.OpenDocSilent(p.FullName, dt, ref odo);
        SwApp.ActivateDoc3(p.FullName,
                           true,
                           (int)SolidWorks.Interop.swconst.swRebuildOnActivation_e.swDontRebuildActiveDoc, ref err);
        success = (SwApp.ActiveDoc as ModelDoc2).SaveAs4(tmpFile, saveVersion, saveOptions, ref err, ref warn);
        try {
            File.Copy(tmpFile, fileName, true);
        } catch (UnauthorizedAccessException uae) {
            throw new Exceptions.BuildPDFException(
                      String.Format("You don't have the reqired permission to access '{0}'.", fileName),
                      uae);
        } catch (ArgumentException ae) {
            throw new Exceptions.BuildPDFException(
                      String.Format("Either '{0}' or '{1}' is not a proper file name.", tmpFile, fileName),
                      ae);
        } catch (PathTooLongException ptle) {
            throw new Exceptions.BuildPDFException(
                      String.Format("Source='{0}'; Dest='{1}' <= One of these is too long.", tmpFile, fileName),
                      ptle);
        } catch (DirectoryNotFoundException dnfe) {
            throw new Exceptions.BuildPDFException(
                      String.Format("Source='{0}'; Dest='{1}' <= One of these is invalid.", tmpFile, fileName),
                      dnfe);
        } catch (FileNotFoundException fnfe) {
            throw new Exceptions.BuildPDFException(
                      String.Format("Crap! I lost '{0}'!", tmpFile),
                      fnfe);
        } catch (IOException) {
            System.Windows.Forms.MessageBox.Show(
                String.Format("If you have the file, '{0}', selected in an Explorer window, " +
                              "you may have to close it.", fileName), "This file is open somewhere.",
                System.Windows.Forms.MessageBoxButtons.OK,
                System.Windows.Forms.MessageBoxIcon.Error);
        } catch (NotSupportedException nse) {
            throw new Exceptions.BuildPDFException(
                      String.Format("Source='{0}'; Dest='{1}' <= One of these is an invalid format.",
                                    tmpFile, fileName), nse);
        }
    }
        // TODO(SIMINT-164) pm.Show() crashes with drag drop
        //[Theory]
        //[InlineData("3_DOF_ARM")]
        public void TestPropertyManagerOpenCloseNotOk(string modelName)
        {
            OpenSWDocument(modelName);

            ExportPropertyManager pm = new ExportPropertyManager(SwApp);

            pm.Show();
            pm.Close(false);
            SwApp.CloseAllDocuments(true);
            Xunit.Assert.True(true, "Property manager failed to open/close with cancel");
        }
        public void TestGetCountNodeCollection(string modelName, int expected)
        {
            ModelDoc2 doc      = OpenSWDocument(modelName);
            LinkNode  baseNode = ConfigurationSerialization.LoadBaseNodeFromModel(doc, out bool abortProcess);

            Assert.False(abortProcess);

            Assert.Equal(expected, CommonSwOperations.GetCount(baseNode.Nodes));

            SwApp.CloseAllDocuments(true);
        }
        public void TestGetTransformationFromMathTransform(double[] matrixData, double[] expected)
        {
            MathUtility   util      = SwApp.GetMathUtility();
            MathTransform transform = util.CreateTransform((object)matrixData);

            double[] result = MathOps.GetTransformation(transform).AsColumnMajorArray();
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], result[i]);
            }
        }
Пример #27
0
        public void TestCreateRobotFromTreeView(string modelName)
        {
            ModelDoc2    doc      = OpenSWDocument(modelName);
            ExportHelper helper   = new ExportHelper(SwApp);
            LinkNode     baseNode = Serialization.LoadBaseNodeFromModel(SwApp, doc, out bool error);

            Assert.False(error);

            helper.CreateRobotFromTreeView(baseNode);
            Assert.NotNull(helper.URDFRobot);
            Assert.True(SwApp.CloseAllDocuments(true));
        }
        public void TestLoadSWComponentsList(string modelName)
        {
            ModelDoc2 doc      = OpenSWDocument(modelName);
            LinkNode  baseNode = ConfigurationSerialization.LoadBaseNodeFromModel(doc, out bool abortProcess);

            Assert.False(abortProcess);
            List <Component2> components = CommonSwOperations.LoadSWComponents(doc, baseNode.Link.SWComponentPIDs);

            Assert.Equal(baseNode.Link.SWComponentPIDs.Count, components.Count);

            SwApp.CloseAllDocuments(true);
        }
        public void TestSaveSWComponentsList(string modelName)
        {
            ModelDoc2   doc     = OpenSWDocument(modelName);
            AssemblyDoc assyDoc = (AssemblyDoc)doc;

            object[]          componentObjs = assyDoc.GetComponents(false);
            List <Component2> components    = componentObjs.Cast <Component2>().ToList();
            List <byte[]>     pids          = Common.SaveSWComponents(doc, components);

            Assert.Equal(pids.Count, components.Count);

            SwApp.CloseAllDocuments(true);
        }
        public void TestRetrieveSWComponentPIDs(string modelName)
        {
            ModelDoc2   doc      = OpenSWDocument(modelName);
            AssemblyDoc assyDoc  = (AssemblyDoc)doc;
            LinkNode    baseNode = Serialization.LoadBaseNodeFromModel(SwApp, doc, out bool abortProcess);

            Assert.False(abortProcess);

            Common.RetrieveSWComponentPIDs(doc, baseNode);
            Assert.Equal(baseNode.Link.SWComponents.Count, baseNode.Link.SWComponentPIDs.Count);

            SwApp.CloseAllDocuments(true);
        }