Пример #1
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();
            }
        }