Exemplo n.º 1
0
        public void SerializationTest()
        {
            var isCylFace = false;
            var areEqual  = false;

            using (var doc = OpenDataDocument("Selections1.SLDPRT"))
            {
                var part = (ISwPart)m_App.Documents.Active;

                var face = SwObjectFactory.FromDispatch <ISwFace>(
                    part.Part.GetEntityByName("Face2", (int)swSelectType_e.swSelFACES) as IFace2, part);

                byte[] bytes;

                using (var memStr = new MemoryStream())
                {
                    face.Serialize(memStr);
                    bytes = memStr.ToArray();
                }

                using (var memStr = new MemoryStream(bytes))
                {
                    var face1 = part.DeserializeObject(memStr);
                    isCylFace = face is ISwCylindricalFace;
                    areEqual  = face1.Dispatch == face.Dispatch;
                }
            }

            Assert.IsTrue(isCylFace);
            Assert.IsTrue(areEqual);
        }
        public IXBody DeserializeBody(Stream stream)
        {
            var comStr = new StreamWrapper(stream);
            var body   = (IBody2)m_Modeler.Restore(comStr);

            return(SwObjectFactory.FromDispatch <ISwTempBody>(body, null));
        }
Exemplo n.º 3
0
        public void GetSketchEntitiesLengthTest()
        {
            double l1;
            double l2;
            double l3;
            double l4;
            double l5;

            using (var doc = OpenDataDocument("Sketch1.SLDPRT"))
            {
                var part = (ISwPart)m_App.Documents.Active;

                var sketch = SwObjectFactory.FromDispatch <ISwSketch2D>(
                    part.Features["Sketch1"].Feature.GetSpecificFeature2() as ISketch, part);

                var segs = sketch.Entities.OfType <IXSketchSegment>().ToArray();

                l1 = segs.OfType <ISwSketchEllipse>().First().Length;
                l2 = segs.OfType <ISwSketchLine>().First().Length;
                l3 = segs.OfType <ISwSketchArc>().First().Length;
                l4 = segs.OfType <ISwSketchSpline>().First().Length;
                l5 = segs.OfType <ISwSketchParabola>().First().Length;
            }

            Assert.That(0.12991965190301241, Is.EqualTo(l1).Within(0.001).Percent);
            Assert.That(0.08468717758758991, Is.EqualTo(l2).Within(0.001).Percent);
            Assert.That(0.10094045912639603, Is.EqualTo(l3).Within(0.001).Percent);
            Assert.That(0.16421451670784409, Is.EqualTo(l4).Within(0.001).Percent);
            Assert.That(0.1034014049596117, Is.EqualTo(l5).Within(0.001).Percent);
        }
Exemplo n.º 4
0
        public void IterateSketchEntitiesTest()
        {
            Type[] entTypes;

            using (var doc = OpenDataDocument("Sketch1.SLDPRT"))
            {
                var part = (ISwPart)m_App.Documents.Active;

                var sketch = SwObjectFactory.FromDispatch <ISwSketch2D>(
                    part.Features["Sketch1"].Feature.GetSpecificFeature2() as ISketch, part);

                entTypes = sketch.Entities.Where(e => !(e is ISwSketchPoint)).Select(e => e.GetType()).ToArray();
            }

            Assert.AreEqual(6, entTypes.Length);
            Assert.IsNotNull(entTypes.FirstOrDefault(t => typeof(ISwSketchEllipse).IsAssignableFrom(t)));
            Assert.IsNotNull(entTypes.FirstOrDefault(t => typeof(ISwSketchLine).IsAssignableFrom(t)));
            Assert.IsNotNull(entTypes.FirstOrDefault(t => typeof(ISwSketchArc).IsAssignableFrom(t)));
            Assert.IsNotNull(entTypes.FirstOrDefault(t => typeof(ISwSketchText).IsAssignableFrom(t)));
            Assert.IsNotNull(entTypes.FirstOrDefault(t => typeof(ISwSketchSpline).IsAssignableFrom(t)));
            Assert.IsNotNull(entTypes.FirstOrDefault(t => typeof(ISwSketchParabola).IsAssignableFrom(t)));
        }
Exemplo n.º 5
0
        public void GetDocumentLdrTest()
        {
            string doc1FileName;
            bool   doc1IsCommitted;

            using (var doc = OpenDataDocument(@"Assembly1\TopAssem1.SLDASM", false, s => s.ViewOnly = true))
            {
                var assm = (ISwAssembly)m_App.Documents.Active;

                assm.Model.Extension.SelectByID2("Part1-1@TopAssem1", "COMPONENT", 0, 0, 0, false, 0, null, 0);

                var swComp = assm.Model.ISelectionManager.GetSelectedObject6(1, -1) as IComponent2;

                var comp = SwObjectFactory.FromDispatch <ISwComponent>(swComp, assm);

                var doc1 = comp.Document;
                doc1FileName    = Path.GetFileName(doc1.Path);
                doc1IsCommitted = doc1.IsCommitted;
            }

            Assert.That(doc1FileName.Equals("Part1.sldprt", StringComparison.CurrentCultureIgnoreCase));
            Assert.IsFalse(doc1IsCommitted);
        }