예제 #1
0
        public static void Run()
        {
            // Set up a navigator which looks at sites/pipes/Nozzles/Tee only
            TypeFilter filt = new TypeFilter();

            filt.Add(DbElementTypeInstance.SITE);
            filt.Add(DbElementTypeInstance.PIPE);
            filt.Add(DbElementTypeInstance.NOZZLE);
            filt.Add(DbElementTypeInstance.TEE);
            CompoundFilter filt2 = new CompoundFilter();

            filt2.AddShow(filt);
            ElementTreeNavigator navi = new ElementTreeNavigator(DbElement.GetElement("/*"), filt2);

            // Test FirstMember
            DbElement site = navi.FirstMemberInScan(Example.Instance.mWorld);
            DbElement nozz = navi.FirstMemberInScan(Example.Instance.mZone);

            nozz = navi.FirstMemberInScan(Example.Instance.mEqui);
            DbElement ele = navi.FirstMemberInScan(nozz);

            // Next
            DbElement zone = site.FirstMember();
            DbElement next = navi.NextInScan(zone);

            // parent
            DbElement parent = navi.Parent(Example.Instance.mEqui);

            parent = navi.Parent(nozz);
            parent = navi.Parent(parent);

            //All Members
            DbElement[] tees = navi.MembersInScan(Example.Instance.mPipe);
        }
예제 #2
0
        private static AxisDir MakeDirection(int num, bool isNeg, DbElement modelEle)
        {
            DbElement cate = modelEle.GetElement(DbAttributeInstance.SPRE).GetElement(DbAttributeInstance.CATR);
            DbElement ptre = cate.GetElement(DbAttributeInstance.PTRE);
            DbElement pt   = ptre.FirstMember();

            while (pt != null && pt.IsValid)
            {
                if (num != pt.GetInteger(DbAttributeInstance.NUMB))
                {
                    pt = pt.Next();
                    continue;
                }

                DbElementType type = pt.GetElementType();
                if (type == DbElementTypeInstance.PTAXIS)
                {
                    return(MakeAxialDirection(num, isNeg, pt, modelEle));
                }
                else if (type == DbElementTypeInstance.PTCAR)
                {
                    return(MakeCartesianDirection(num, isNeg, pt, modelEle));
                }
                else if (type == DbElementTypeInstance.PTMIX)
                {
                    return(MakeMixedDirection(num, isNeg, pt, modelEle));
                }
                else if (type == DbElementTypeInstance.PTPOS)
                {
                    return(MakePositionTypeDirection(num, isNeg, pt, modelEle));
                }
                pt = pt.Next();
            }
            return(null);
        }
예제 #3
0
        private void ExportBranch(DbElement branchEle, D3Transform transform, int color)
        {
            int       curCol = GetColor(branchEle, color);
            DbElement ele    = branchEle.FirstMember();

            while (ele != null && ele.IsValid)
            {
                if (IsReadableEle(ele))
                {
                    ExportPipeItem(ele, transform, curCol);
                }
                ele = ele.Next();
            }
        }
예제 #4
0
        private void ExportPipe(DbElement pipeEle, D3Transform transform, int color)
        {
            int       curCol = GetColor(pipeEle, color);
            DbElement ele    = pipeEle.FirstMember();

            while (ele != null && ele.IsValid)
            {
                if (IsReadableEle(ele) && ele.GetElementType() == DbElementTypeInstance.BRANCH)
                {
                    ExportBranch(ele, transform, curCol);
                }
                ele = ele.Next();
            }
        }
예제 #5
0
        private void ExportWorld(DbElement worldEle)
        {
            int       color = GetColor(worldEle, System.Drawing.Color.White.ToArgb());
            DbElement ele   = worldEle.FirstMember();

            while (ele != null && ele.IsValid)
            {
                if (IsReadableEle(ele) && ele.GetElementType() == DbElementTypeInstance.SITE)
                {
                    ExportSite(ele, color);
                }
                ele = ele.Next();
            }
        }
예제 #6
0
        private void ExportSite(DbElement siteEle, int color)
        {
            int         curCol    = GetColor(siteEle, color);
            D3Transform transform = GetTransform(siteEle);
            DbElement   ele       = siteEle.FirstMember();

            while (ele != null && ele.IsValid)
            {
                if (IsReadableEle(ele) && ele.GetElementType() == DbElementTypeInstance.ZONE)
                {
                    ExportZone(ele, transform, curCol);
                }
                ele = ele.Next();
            }
        }
예제 #7
0
        public DbElement BoreSele(double bore)
        {
            Console.WriteLine(FirstSele.FullName() + " looking for boreSele with size: " + bore.ToString());
            DbElement boreSele = FirstSele.Members().SingleOrDefault(m => m.GetDouble(DbAttributeInstance.ANSW) == bore);

            if (boreSele == null || boreSele.IsValid == false)
            {
                Console.WriteLine("Adding new BORE SELE");
                boreSele = FirstSele.CreateLast(DbElementTypeInstance.SELEC);
                boreSele.SetAttribute(DbAttributeInstance.ANSW, bore);
                boreSele.SetAttribute(DbAttributeInstance.MAXA, bore);
                boreSele.SetAttribute(DbAttributeInstance.QUES, "SHOP");

                DbElement shopSele = boreSele.CreateLast(DbElementTypeInstance.SELEC);
                shopSele.SetAttribute(DbAttributeInstance.TANS, "TRUE");
                shopSele.SetAttribute(DbAttributeInstance.QUES, "STYP");
            }

            return(boreSele.FirstMember());
        }
예제 #8
0
        private void ExportZone(DbElement zoneEle, D3Transform transform, int color)
        {
            int         curCol           = GetColor(zoneEle, color);
            D3Transform currentTransform = transform.Multiply(GetTransform(zoneEle));
            DbElement   ele = zoneEle.FirstMember();

            while (ele != null && ele.IsValid)
            {
                if (IsReadableEle(ele))
                {
                    if (ele.GetElementType() == DbElementTypeInstance.PIPE)
                    {
                        ExportPipe(ele, currentTransform, curCol);
                    }
                    else if (ele.GetElementType() == DbElementTypeInstance.EQUIPMENT)
                    {
                        ExportEquip(ele, currentTransform, curCol);
                    }
                }
                ele = ele.Next();
            }
        }
예제 #9
0
        public Buildable Convert(DbElement element)
        {
            Size      size      = new Size();
            Position  position  = new Position();
            Direction direction = new Direction();

            size.Height = element.GetDouble(DbAttributeInstance.HEIG);

            var q = new DbQualifier();

            q.wrtQualifier = element.OwnerInHierarchyOfType(DbElementTypeInstance.EQUIPMENT);

            var pos = element.GetPosition(DbAttributeInstance.POS, q);

            position.X = pos.X;
            position.Y = pos.Y;
            position.Z = pos.Z;

            var orientation = element.GetOrientation(DbAttributeInstance.ORI, q);

            direction.X = orientation.XDir().ToString();
            direction.Y = orientation.YDir().ToString();
            direction.Z = orientation.ZDir().ToString();

            var vertPos = new List <Position>();

            foreach (var vert in element.FirstMember().Members())
            {
                pos = vert.GetPosition(DbAttributeInstance.POS);
                var vp = new Position();
                vp.X = pos.X;
                vp.Y = pos.Y;
                vp.Z = pos.Z;

                vertPos.Add(vp);
            }

            return(new Buildable(DbElementTypeInstance.SEXTRUSION, element, size, position, direction, vertPos));
        }
예제 #10
0
		private void ExportEquip(DbElement equipEle, D3Transform transform, int parentColor)
		{
			int color = GetColor(equipEle, parentColor);
			D3Transform currTrans = transform.Multiply(GetTransform(equipEle));
			DbElement ele = equipEle.FirstMember();
			while (ele != null && ele.IsValid)
			{
				if (IsReadableEle(ele))
				{
					if (!IsVisible(ele))
					{
						ele = ele.Next();
						continue;
					}

					DbElementType eleType = ele.GetElementType();
					if (eleType == DbElementTypeInstance.NOZZLE)
						ExportPipeItem(ele, currTrans, parentColor);
					else if (eleType == DbElementTypeInstance.TMPLATE)
					{
						DbElement[] lcnfArray = null;
						if (ele.IsAttributeValid(DbAttributeInstance.LCNFA))
						{
							lcnfArray = ele.GetElementArray(DbAttributeInstance.LCNFA);
						}

						if (lcnfArray == null || lcnfArray.Length <= 0)
						{
							DbElement tmplEle = ele.FirstMember();
							while (tmplEle != null && tmplEle.IsValid)
							{
								if (IsReadableEle(tmplEle) && IsVisible(tmplEle))
									ExportDesignGeomotry(tmplEle, currTrans, color);
								tmplEle = tmplEle.Next();
							}
						}
						else
						{
							foreach (DbElement lcnfEle in lcnfArray)
							{
								if (IsReadableEle(lcnfEle) && IsVisible(lcnfEle))
									ExportDesignGeomotry(lcnfEle, currTrans, color);
							}
						}
					}
					else if (eleType == DbElementTypeInstance.SUBEQUIPMENT)
					{
						ExportEquip(ele, currTrans, color);
					}
					else
						ExportDesignGeomotry(ele, currTrans, color);
					
				}
				ele = ele.Next();
			}
		}
예제 #11
0
		private void ExportBranch(DbElement branchEle, D3Transform transform, int color)
		{
			int curCol = GetColor(branchEle, color);
			DbElement ele = branchEle.FirstMember();
			while (ele != null && ele.IsValid)
			{
				if (IsReadableEle(ele))
					ExportPipeItem(ele, transform, curCol);
				ele = ele.Next();
			}
		}
예제 #12
0
		private void ExportPipe(DbElement pipeEle, D3Transform transform, int color)
		{
			int curCol = GetColor(pipeEle, color);
			DbElement ele = pipeEle.FirstMember();
			while (ele != null && ele.IsValid)
			{
				if (IsReadableEle(ele) && ele.GetElementType() == DbElementTypeInstance.BRANCH)
					ExportBranch(ele, transform, curCol);
				ele = ele.Next();
			}
		}
예제 #13
0
		private void ExportZone(DbElement zoneEle, D3Transform transform, int color)
		{
			int curCol = GetColor(zoneEle, color);
			D3Transform currentTransform = transform.Multiply(GetTransform(zoneEle));
			DbElement ele = zoneEle.FirstMember();
			while (ele != null && ele.IsValid)
			{
				if (IsReadableEle(ele))
				{
					if (ele.GetElementType() == DbElementTypeInstance.PIPE)
						ExportPipe(ele, currentTransform, curCol);
					else if (ele.GetElementType() == DbElementTypeInstance.EQUIPMENT)
						ExportEquip(ele, currentTransform, curCol);
				}
				ele = ele.Next();
			}
		}
예제 #14
0
		private void ExportSite(DbElement siteEle, int color)
		{
			int curCol = GetColor(siteEle, color);
			D3Transform transform = GetTransform(siteEle);
			DbElement ele = siteEle.FirstMember();
			while (ele != null && ele.IsValid)
			{
				if (IsReadableEle(ele) && ele.GetElementType() == DbElementTypeInstance.ZONE)
					ExportZone(ele, transform, curCol);
				ele = ele.Next();
			}
		}
예제 #15
0
		private void ExportWorld(DbElement worldEle)
		{
			int color = GetColor(worldEle, System.Drawing.Color.White.ToArgb());
			DbElement ele = worldEle.FirstMember();
			while (ele != null && ele.IsValid)
			{
				if (IsReadableEle(ele) && ele.GetElementType() == DbElementTypeInstance.SITE)
					ExportSite(ele, color);
				ele = ele.Next();
			}
		}
예제 #16
0
        private void ExportPipeItem(DbElement ele, D3Transform transform, int color)
        {
            if (ele.GetElementType() == DbElementTypeInstance.TUBING)
            {
                ExportTube(ele, transform, color);
                return;
            }

            DbElement specEle = null;

            if ((specEle = ele.GetElement(DbAttributeInstance.SPRE)) == null ||
                !IsReadableEle(specEle) ||
                ele.GetElementType() == DbElementTypeInstance.ATTACHMENT
                )
            {
                return;;
            }

            DbElement cateEle = null;

            if ((cateEle = specEle.GetElement(DbAttributeInstance.CATR)) == null || !IsReadableEle(cateEle))
            {
                return;
            }

            DbElement gmEle = null;

            if ((gmEle = cateEle.GetElement(DbAttributeInstance.GMRE)) == null || !IsReadableEle(gmEle))
            {
                return;
            }

            D3Transform eleTrans = transform.Multiply(GetTransform(ele));

            DbElement gEle = gmEle.FirstMember();

            while (gEle != null && gEle.IsValid)
            {
                if (IsReadableEle(gEle) && gEle.GetBool(DbAttributeInstance.TUFL))
                {
                    if (!IsVisible(gEle))
                    {
                        gEle = gEle.Next();
                        continue;
                    }

                    try
                    {
                        if (gEle.GetElementType() == DbElementTypeInstance.SCYLINDER)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAXI);
                            AxisDir paxi = EvalDirection.Eval(ele, expr);

                            double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);
                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
                            double pdis = GetExper(gEle, DbAttributeInstance.PDIS).Eval(ele);

                            D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
                            D3Point  pos = eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos));

                            Cylinder cyl = new Cylinder();
                            cyl.Org = new Point(pos)
                                      .MoveBy(dir, pdis);
                            cyl.Height = new Point(dir).Mul(phei);
                            cyl.Radius = pdia / 2.0;
                            cyl.Color  = color;
                            session.Save(cyl);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.LCYLINDER)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAXI);
                            AxisDir paxi = EvalDirection.Eval(ele, expr);

                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
                            double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);
                            double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);

                            D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
                            D3Point  pos = eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos));

                            Cylinder cyl = new Cylinder();
                            cyl.Org = new Point(pos)
                                      .MoveBy(dir, pbdi);
                            cyl.Height = new Point(dir).Mul(ptdi - pbdi);
                            cyl.Radius = pdia / 2.0;
                            cyl.Color  = color;
                            session.Save(cyl);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.SBOX)
                        {
                            double pxlen = GetExper(gEle, DbAttributeInstance.PXLE).Eval(ele);
                            double pylen = GetExper(gEle, DbAttributeInstance.PYLE).Eval(ele);
                            double pzlen = GetExper(gEle, DbAttributeInstance.PZLE).Eval(ele);
                            double px    = GetExper(gEle, DbAttributeInstance.PX).Eval(ele);
                            double py    = GetExper(gEle, DbAttributeInstance.PY).Eval(ele);
                            double pz    = GetExper(gEle, DbAttributeInstance.PZ).Eval(ele);

                            Point xlen = new Point(eleTrans.Multiply(D3Vector.D3EAST));
                            Point ylen = new Point(eleTrans.Multiply(D3Vector.D3NORTH));
                            Point zlen = new Point(eleTrans.Multiply(D3Vector.D3UP));

                            Point pos = new Point(eleTrans.Multiply(GeometryUtility.Org));
                            pos.MoveBy(xlen, px - pxlen / 2.0).MoveBy(ylen, py - pylen / 2.0).MoveBy(zlen, pz - pzlen / 2.0);
                            xlen.Mul(pxlen);
                            ylen.Mul(pylen);
                            zlen.Mul(pzlen);

                            Box box = new Box();
                            box.Org   = pos;
                            box.XLen  = xlen;
                            box.YLen  = ylen;
                            box.ZLen  = zlen;
                            box.Color = color;
                            session.Save(box);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.SCTORUS)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAAX);
                            AxisDir paax = EvalDirection.Eval(ele, expr);

                            expr = gEle.GetAsString(DbAttributeInstance.PBAX);
                            AxisDir pbax = EvalDirection.Eval(ele, expr);

                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);

                            CircularTorus ct     = new CircularTorus();
                            Direction     normal = null;
                            if (!paax.Dir.IsParallel(pbax.Dir))
                            {
                                normal = paax.Dir.Orthogonal(pbax.Dir);
                            }
                            else
                            {
                                normal = paax.Dir.Orthogonal(Direction.Create(paax.Pos, pbax.Pos));
                            }
                            ct.Normal = new Point(eleTrans.Multiply(GeometryUtility.ToD3VectorRef(normal)));

                            ct.StartPnt    = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(pbax.Pos)));
                            ct.StartRadius = ct.EndRadius = pdia / 2.0;

                            double mRadius = 0.0;
                            if (!paax.Dir.IsParallel(pbax.Dir))
                            {
                                double ang = paax.Dir.Angle(pbax.Dir) * Math.PI / 180.0;
                                ct.Angle = Math.PI - ang;
                                ang     /= 2.0;
                                double len = paax.Pos.Distance(pbax.Pos) / 2;
                                mRadius = len / Math.Sin(ang) * Math.Tan(ang);
                            }
                            else
                            {
                                ct.Angle = Math.PI;
                                mRadius  = paax.Pos.Distance(pbax.Pos) / 2.0;
                            }
                            D3Vector radiusDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir.Orthogonal(normal)));
                            ct.Center = new Point(ct.StartPnt).MoveBy(radiusDir, mRadius);
                            ct.Color  = color;

                            session.Save(ct);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.SRTORUS)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAAX);
                            AxisDir paax = EvalDirection.Eval(ele, expr);

                            expr = gEle.GetAsString(DbAttributeInstance.PBAX);
                            AxisDir pbax = EvalDirection.Eval(ele, expr);

                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
                            double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);

                            RectangularTorus rt     = new RectangularTorus();
                            Direction        normal = null;
                            if (!paax.Dir.IsParallel(pbax.Dir))
                            {
                                normal = paax.Dir.Orthogonal(pbax.Dir);
                            }
                            else
                            {
                                normal = paax.Dir.Orthogonal(Direction.Create(paax.Pos, pbax.Pos));
                            }
                            rt.Normal = new Point(eleTrans.Multiply(GeometryUtility.ToD3VectorRef(normal)));

                            rt.StartPnt    = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(pbax.Pos)));
                            rt.StartWidth  = rt.EndWidth = pdia;
                            rt.StartHeight = rt.EndHeight = phei;

                            double mRadius = 0.0;
                            if (!paax.Dir.IsParallel(pbax.Dir))
                            {
                                double ang = paax.Dir.Angle(pbax.Dir) * Math.PI / 180.0;
                                rt.Angle = Math.PI - ang;
                                ang     /= 2.0;
                                double len = paax.Pos.Distance(pbax.Pos) / 2;
                                mRadius = len / Math.Sin(ang) * Math.Tan(ang);
                            }
                            else
                            {
                                rt.Angle = Math.PI;
                                mRadius  = paax.Pos.Distance(pbax.Pos) / 2.0;
                            }
                            D3Vector radiusDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir.Orthogonal(normal)));
                            rt.Center = new Point(rt.StartPnt).MoveBy(radiusDir, mRadius);
                            rt.Color  = color;

                            session.Save(rt);
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.LSNOUT)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAAX);
                            AxisDir paax = EvalDirection.Eval(ele, expr);

                            expr = gEle.GetAsString(DbAttributeInstance.PBAX);
                            AxisDir pbax = EvalDirection.Eval(ele, expr);

                            double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);
                            double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);
                            double ptdm = GetExper(gEle, DbAttributeInstance.PTDM).Eval(ele);
                            double pbdm = GetExper(gEle, DbAttributeInstance.PBDM).Eval(ele);
                            double poff = GetExper(gEle, DbAttributeInstance.POFF).Eval(ele);

                            D3Vector tdir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paax.Dir));
                            D3Point  pos  = eleTrans.Multiply(GeometryUtility.ToD3Point(paax.Pos));
                            D3Vector bdir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir));

                            if (pbdm < 1.0e-5 || ptdm < 1.0e-5)
                            {
                                Cone cone = new Cone();
                                cone.Radius = pbdm > ptdm ? pbdm / 2.0 : ptdm / 2.0;
                                cone.Org    = new Point(pos).MoveBy(tdir, pbdi);
                                cone.Offset = new Point(bdir).Mul(poff);
                                cone.Height = new Point(tdir).Mul(ptdi - pbdi);
                                cone.Color  = color;
                                session.Save(cone);
                            }
                            else
                            {
                                Snout snout = new Snout();
                                snout.BottomRadius = pbdm / 2.0;
                                snout.TopRadius    = ptdm / 2.0;
                                snout.Org          = new Point(pos).MoveBy(tdir, pbdi);
                                snout.Offset       = new Point(bdir).Mul(poff);
                                snout.Height       = new Point(tdir).Mul(ptdi - pbdi);
                                snout.Color        = color;
                                session.Save(snout);
                            }
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.SDSH)
                        {
                            string  expr = gEle.GetAsString(DbAttributeInstance.PAXI);
                            AxisDir paxi = EvalDirection.Eval(ele, expr);

                            double phei = GetExper(gEle, DbAttributeInstance.PHEI).Eval(ele);
                            double pdia = GetExper(gEle, DbAttributeInstance.PDIA).Eval(ele);
                            double pdis = GetExper(gEle, DbAttributeInstance.PDIS).Eval(ele);
                            double prad = GetExper(gEle, DbAttributeInstance.PRAD).Eval(ele);

                            D3Vector dir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paxi.Dir));
                            if (prad > 0.0)
                            {
                                Ellipsoid ellipsoid = new Ellipsoid();
                                ellipsoid.Center = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos)))
                                                   .MoveBy(dir, pdis);
                                ellipsoid.ALen    = new Point(dir).Mul(phei);
                                ellipsoid.BRadius = pdia / 2.0;
                                ellipsoid.Color   = color;
                                session.Save(ellipsoid);
                            }
                            else
                            {
                                Sphere sphere = new Sphere();
                                sphere.Center = new Point(eleTrans.Multiply(GeometryUtility.ToD3Point(paxi.Pos)))
                                                .MoveBy(dir, pdis);
                                double bottomRadius = pdia / 2.0;
                                sphere.Radius       = (bottomRadius * bottomRadius + phei * phei) / 2.0 / phei;
                                sphere.BottomNormal = new Point(-dir);
                                double angle = Math.PI / 2.0 - Math.Asin(2.0 * bottomRadius * phei / (bottomRadius * bottomRadius + phei * phei));
                                if (bottomRadius >= phei)
                                {
                                    sphere.Angle = Math.PI - angle * 2.0;
                                }
                                else
                                {
                                    sphere.Angle = Math.PI + angle * 2.0;
                                }
                                sphere.Color = color;
                                session.Save(sphere);
                            }
                        }
                        else if (gEle.GetElementType() == DbElementTypeInstance.LPYRAMID)
                        {
                            string  exper = gEle.GetAsString(DbAttributeInstance.PAAX);
                            AxisDir paax  = EvalDirection.Eval(ele, exper);
                            exper = gEle.GetAsString(DbAttributeInstance.PBAX);
                            AxisDir pbax = EvalDirection.Eval(ele, exper);
                            exper = gEle.GetAsString(DbAttributeInstance.PCAX);
                            AxisDir pcax = EvalDirection.Eval(ele, exper);

                            double pbtp = GetExper(gEle, DbAttributeInstance.PBTP).Eval(ele);
                            double pctp = GetExper(gEle, DbAttributeInstance.PCTP).Eval(ele);
                            double pbbt = GetExper(gEle, DbAttributeInstance.PBBT).Eval(ele);
                            double pcbt = GetExper(gEle, DbAttributeInstance.PCBT).Eval(ele);
                            double pbof = GetExper(gEle, DbAttributeInstance.PBOF).Eval(ele);
                            double pcof = GetExper(gEle, DbAttributeInstance.PCOF).Eval(ele);
                            double ptdi = GetExper(gEle, DbAttributeInstance.PTDI).Eval(ele);
                            double pbdi = GetExper(gEle, DbAttributeInstance.PBDI).Eval(ele);

                            D3Vector zDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(paax.Dir));
                            D3Vector xDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pbax.Dir));
                            D3Vector yDir = eleTrans.Multiply(GeometryUtility.ToD3VectorRef(pcax.Dir));
                            D3Point  org  = eleTrans.Multiply(GeometryUtility.ToD3Point(paax.Pos));
                            org.MoveBy(zDir * pbdi);

                            double height = ptdi - pbdi;

                            Pyramid pyramid = new Pyramid();
                            pyramid.Org        = new Point(org);
                            pyramid.Height     = new Point(zDir).Mul(height);
                            pyramid.XAxis      = new Point(xDir);
                            pyramid.BottomXLen = pbbt;
                            pyramid.BottomYLen = pcbt;
                            pyramid.TopXLen    = pbtp;
                            pyramid.TopYLen    = pctp;
                            pyramid.Offset     = new Point(xDir * pbof + yDir * pcof);
                            pyramid.Color      = color;
                            session.Save(pyramid);
                        }
                    }
                    catch (System.NullReferenceException)
                    {
                    }
                    catch (System.Exception)
                    {
                        System.Console.WriteLine("Ele = " + ele.GetAsString(DbAttributeInstance.NAME));
                        System.Console.WriteLine("GEle = " + gEle.GetAsString(DbAttributeInstance.NAME));
                        throw;
                    }
                }
                gEle = gEle.Next();
            }
        }
예제 #17
0
        private void ExportEquip(DbElement equipEle, D3Transform transform, int parentColor)
        {
            int         color     = GetColor(equipEle, parentColor);
            D3Transform currTrans = transform.Multiply(GetTransform(equipEle));
            DbElement   ele       = equipEle.FirstMember();

            while (ele != null && ele.IsValid)
            {
                if (IsReadableEle(ele))
                {
                    if (!IsVisible(ele))
                    {
                        ele = ele.Next();
                        continue;
                    }

                    DbElementType eleType = ele.GetElementType();
                    if (eleType == DbElementTypeInstance.NOZZLE)
                    {
                        ExportPipeItem(ele, currTrans, parentColor);
                    }
                    else if (eleType == DbElementTypeInstance.TMPLATE)
                    {
                        DbElement[] lcnfArray = null;
                        if (ele.IsAttributeValid(DbAttributeInstance.LCNFA))
                        {
                            lcnfArray = ele.GetElementArray(DbAttributeInstance.LCNFA);
                        }

                        if (lcnfArray == null || lcnfArray.Length <= 0)
                        {
                            DbElement tmplEle = ele.FirstMember();
                            while (tmplEle != null && tmplEle.IsValid)
                            {
                                if (IsReadableEle(tmplEle) && IsVisible(tmplEle))
                                {
                                    ExportDesignGeomotry(tmplEle, currTrans, color);
                                }
                                tmplEle = tmplEle.Next();
                            }
                        }
                        else
                        {
                            foreach (DbElement lcnfEle in lcnfArray)
                            {
                                if (IsReadableEle(lcnfEle) && IsVisible(lcnfEle))
                                {
                                    ExportDesignGeomotry(lcnfEle, currTrans, color);
                                }
                            }
                        }
                    }
                    else if (eleType == DbElementTypeInstance.SUBEQUIPMENT)
                    {
                        ExportEquip(ele, currTrans, color);
                    }
                    else
                    {
                        ExportDesignGeomotry(ele, currTrans, color);
                    }
                }
                ele = ele.Next();
            }
        }
        public static void Run()
        {
            //Get element type
            int           hash = DbElementTypeInstance.EQUIPMENT.GetHashCode();
            DbElementType type = DbElementType.GetElementType(hash);

            // Get system attributes
            DbAttribute[] atts = DbElementTypeInstance.EQUIPMENT.SystemAttributes();
            int           size = atts.Length;

            //Construct equi1
            DbElement equi1 = DbElement.GetElement("/ExampleEqui");

            //Create equi2 after equi1
            DbElement equi2 = equi1.CreateAfter(DbElementTypeInstance.EQUIPMENT);

            //Copy equi1 to equi2
            equi2.Copy(equi1);

            //Copy hierarchy
            DbCopyOption options = new DbCopyOption();

            options.FromName = "ExampleEqui";
            options.ToName   = "equi2";
            options.Rename   = true;
            equi2.CopyHierarchy(equi1, options);
            DbElement first = equi2.FirstMember();

            //Copy after last
            equi1.InsertAfterLast(Example.Instance.mZone);

            //Branch to head tube
            DbElement headTube     = Example.Instance.mBran.FirstMember();
            string    headTubeName = headTube.GetString(DbAttributeInstance.NAME);

            //Next Prev
            DbElement nextElement = headTube.Next();
            DbElement prevElement = nextElement.Previous;

            //First Member of given type
            DbElement nozz1 = Example.Instance.mEqui.FirstMember(DbElementTypeInstance.NOZZLE);

            //Next element of given type
            DbElement nozz2 = nozz1.Next(DbElementTypeInstance.NOZZLE);

            //Get Members
            DbElement[] members = Example.Instance.mBran.Members();

            //Get Members of given type
            DbElement[] nozzles = Example.Instance.mEqui.Members(DbElementTypeInstance.NOZZLE);

            //Get nth Member
            DbElement mem = Example.Instance.mEqui.Member(2);

            //Expressions
            DbElement[] eles;
            eles  = Example.Instance.mEqui.GetElementArray(DbAttribute.GetDbAttribute("MEMB"), DbElementType.GetElementType("NOZZ"));
            nozz1 = eles[1];
            DbExpression    expr1 = DbExpression.Parse("HEIGHT OF PREV * 2");
            string          val   = expr1.ToString();
            double          dval;
            DbAttributeUnit units = DbAttributeUnit.DIST;

            dval = nozz1.EvaluateDouble(expr1, units);
            DbExpression expr2 = DbExpression.Parse("12");

            dval = nozz1.EvaluateDouble(expr2, units);

            //Rules
            DbExpression     expr   = DbExpression.Parse("HEIGHT * 2.0");
            DbRuleStatus     status = DbRuleStatus.DYNAMIC;
            DbExpressionType etype  = DbExpressionType.REAL;
            DbRule           rule   = DbRule.CreateDbRule(expr, status, etype);

            Example.Instance.mCyli.SetRule(DbAttribute.GetDbAttribute("DIAM"), rule);
            DbRule rule1 = Example.Instance.mCyli.GetRule(DbAttribute.GetDbAttribute("DIAM"));
            string text  = rule1.ToString();

            //Delete/Exists Rule
            Example.Instance.mCyli.DeleteRule(DbAttribute.GetDbAttribute("DIAM"));
            bool exists = Example.Instance.mCyli.ExistRule(DbAttribute.GetDbAttribute("DIAM"));

            Example.Instance.mCyli.SetRule(DbAttribute.GetDbAttribute("DIAM"), rule1);
            exists = Example.Instance.mCyli.ExistRule(DbAttribute.GetDbAttribute("DIAM"));

            //Change attribute
            Example.Instance.mCyli.SetAttribute(DbAttribute.GetDbAttribute("DIAM"), 1000.0F);
            double diam = Example.Instance.mCyli.GetDouble(DbAttribute.GetDbAttribute("DIAM"));

            //verify rule
            bool diff = Example.Instance.mCyli.VerifyRule(DbAttribute.GetDbAttribute("DIAM"));

            //execute rule
            Example.Instance.mCyli.ExecuteRule(DbAttribute.GetDbAttribute("DIAM"));
            diam = Example.Instance.mCyli.GetDouble(DbAttribute.GetDbAttribute("DIAM"));

            //verify rule again
            diff = Example.Instance.mCyli.VerifyRule(DbAttribute.GetDbAttribute("DIAM"));

            //change some attributes
            Example.Instance.mCyli.SetAttribute(DbAttribute.GetDbAttribute("DIAM"), 1000.0F);
            diam = Example.Instance.mCyli.GetDouble(DbAttribute.GetDbAttribute("DIAM"));

            //Now execute all rules under equi
            Example.Instance.mEqui.ExecuteAllRules();
            diam = Example.Instance.mCyli.GetDouble(DbAttribute.GetDbAttribute("DIAM"));

            //Propagate rules
            Example.Instance.mCyli.SetAttribute(DbAttribute.GetDbAttribute("DIAM"), 1000.0F);
            Example.Instance.mCyli.PropagateRules(DbAttribute.GetDbAttribute("DIAM"));

            //Claim/Release
            Example.Instance.mEqui.Claim();
            bool claimed = Example.Instance.mEqui.GetBool(DbAttribute.GetDbAttribute("LCLM"));

            //release equi
            MDB.CurrentMDB.SaveWork("Save Example");
            Example.Instance.mEqui.Release();
            claimed = Example.Instance.mEqui.GetBool(DbAttribute.GetDbAttribute("LCLM"));

            //Claim hierarchy
            try
            {
                Example.Instance.mEqui.ClaimHierarchy();
            }
            catch (PdmsException ex)
            {
            }
            claimed = Example.Instance.mEqui.GetBool(DbAttribute.GetDbAttribute("LCLMH"));

            //release all equi
            Example.Instance.mEqui.ReleaseHierarchy();
            claimed = Example.Instance.mEqui.GetBool(DbAttribute.GetDbAttribute("LCLM"));

            //change type
            string stype = Example.Instance.mTee.GetElementType().ToString();

            Example.Instance.mTee.ChangeType(DbElementType.GetElementType("OLET"));
            stype = Example.Instance.mTee.GetElementType().ToString();

            //UDA at default
            string      special = "Test UDA";
            DbAttribute uda     = DbAttribute.GetDbAttribute(":SPECIAL");

            if (uda != null)
            {
                Example.Instance.mElbo.SetAttribute(uda, special);
                special = Example.Instance.mElbo.GetString(uda);
                bool dflt = Example.Instance.mElbo.AtDefault(uda);

                //is one element above another in the hierarchy
                bool result = Example.Instance.mSite.IsDescendant(Example.Instance.mZone);
                result = Example.Instance.mZone.IsDescendant(Example.Instance.mSite);

                //Set uda to default
                Example.Instance.mElbo.SetAttributeDefault(uda);
                special = Example.Instance.mElbo.GetString(uda);
                dflt    = Example.Instance.mElbo.AtDefault(uda);
            }
        }