Esempio n. 1
0
        public void CreateElement(string groupel, string ingroupel, string iningroupel, double getPosX, double getPosY, double getPosZ, double getLenX, double getLenY, double getLenZ, int getAngleX, int getAngleY, int getAngleZ, int idmaterial, ModelUIElement3D thisobject1, double otx, double oty, double otz, string text = "-1", int id = -1)
        {
            if (text == "-1")
            {
                text = win.soureseDefault;
            }
            if (id == -1)
            {
                id = win.iddefaultB;
            }
            ModelImporter importer  = new ModelImporter();
            Material      material1 = new DiffuseMaterial(win.defcolor);

            importer.DefaultMaterial = material1;
            string           request          = "select sourse from elements where id=" + idmaterial;
            NpgsqlConnection npgSqlConnection = new NpgsqlConnection(win.connectionString);

            npgSqlConnection.Open();
            NpgsqlCommand    npgSqlCommand = new NpgsqlCommand(request, npgSqlConnection);
            NpgsqlDataReader reader        = npgSqlCommand.ExecuteReader();
            string           str           = "";

            while (reader.Read())
            {
                str = reader.GetString(0);
            }
            Model3DGroup model = new Model3DGroup();

            model = importer.Load(str);
            double maxx = 0;
            int    idd  = win.rand.Next(0, 100000);
            double xx   = 9999;
            double yy   = 9999;
            double zz   = 9999;

            for (int i = 0; i < model.Children.Count; i++)
            {
                GeometryModel3D   gmodel = model.Children[i] as GeometryModel3D;
                MeshGeometry3D    mmodel = (MeshGeometry3D)gmodel.Geometry;
                Point3DCollection p3dc   = mmodel.Positions;
                if (gmodel.Bounds.SizeX > maxx)
                {
                    maxx = gmodel.Bounds.SizeX;
                }
                if (gmodel.Bounds.SizeY > maxx)
                {
                    maxx = gmodel.Bounds.SizeY;
                }
                if (gmodel.Bounds.SizeZ > maxx)
                {
                    maxx = gmodel.Bounds.SizeZ;
                }
                if (gmodel.Bounds.X < xx)
                {
                    xx = gmodel.Bounds.X;
                }
                if (gmodel.Bounds.Y < yy)
                {
                    yy = gmodel.Bounds.Y;
                }
                if (gmodel.Bounds.Z < zz)
                {
                    zz = gmodel.Bounds.Z;
                }
            }
            for (int i = 0; i < model.Children.Count; i++)
            {
                GeometryModel3D   gmodel = model.Children[i] as GeometryModel3D;
                MeshGeometry3D    mmodel = (MeshGeometry3D)gmodel.Geometry;
                Point3DCollection p3dc   = mmodel.Positions;
                gmodel.Material = new DiffuseMaterial(win.defcolor);
                for (int ii = 0; ii < p3dc.Count; ii++)
                {
                    Point3D tp = p3dc[ii];
                    tp.X     = tp.X / maxx;
                    tp.Y     = tp.Y / maxx;
                    tp.Z     = tp.Z / maxx;
                    p3dc[ii] = tp;
                }
                for (int ii = 0; ii < p3dc.Count; ii++)
                {
                    Point3D tp = p3dc[ii];
                    tp.X     = tp.X - xx / maxx;
                    tp.Y     = tp.Y - yy / maxx;
                    tp.Z     = tp.Z - zz / maxx;
                    p3dc[ii] = tp;
                }
                ModelUIElement3D modelUI = new ModelUIElement3D();
                modelUI.Model = gmodel;
                ElementCabinet tempmodel = new ElementCabinet(modelUI, 1, 1, 1, 0, 0, 0);
                tempmodel.idtexture   = id;
                tempmodel.groupel     = groupel;
                tempmodel.ingroupel   = ingroupel;
                tempmodel.iningroupel = iningroupel;
                tempmodel.hashtable   = win.CreatedElements;
                win.CreatedElements.Add(modelUI.GetHashCode(), tempmodel);
                win.container.Children.Add(modelUI);
                modelUI.MouseUp += win.ClickOnModel;
                tempmodel.LenZ   = 2;
                tempmodel.changeObjectLen(getLenX, getLenY, getLenZ);
                tempmodel.changeObjectPos(getPosX, getPosY, getPosZ);
                tempmodel.ChangeAngleX(getAngleX);
                tempmodel.ChangeAngleY(getAngleY);
                tempmodel.ChangeAngleZ(getAngleZ);
                tempmodel.idelement          = idmaterial;
                tempmodel.select             = win.CreatedElements[thisobject1.GetHashCode()] as ElementCabinet;
                tempmodel.otsx               = otx;
                tempmodel.otsy               = oty;
                tempmodel.otsz               = otz;
                tempmodel.thismodel.Material = new DiffuseMaterial(new SolidColorBrush(win.defcolor.Color));
            }
        }