コード例 #1
0
        private void button_swap_Click(object sender, RoutedEventArgs e)
        {
            if (comboBox_new.SelectedIndex > -1 && comboBox_old.SelectedIndex > -1)
            {
                dynamic blocktoreplace = blockstoreplace[comboBox_old.SelectedIndex];
                dynamic replacebyblock = replacebyblocks[comboBox_new.SelectedIndex];
                int     amountchanged  = 0;
                dynamic blueprint      = BP.Blueprint;
                foreach (dynamic body in blueprint.bodies)
                {
                    foreach (dynamic child in body.childs)
                    {
                        if (child.shapeId == blocktoreplace.uuid && (textBox_color1.Text.ToString().ToLower() == child.color.ToString().ToLower() || textBox_color1.Text.ToString().ToLower() == "#" + child.color.ToString().ToLower() || textBox_color1.Text == "" || textBox_color1.Text == "#"))
                        {
                            if (child.bounds == null)
                            {
                                child.bounds = blocktoreplace.bounds;
                            }
                            child.shapeId = replacebyblock.uuid;
                            amountchanged++;
                        }
                    }
                }

                string message = "++ " + amountchanged + " " + blocktoreplace.name + " are now changed to " + replacebyblock.name;
                MessageBox.Show(message);
                if (amountchanged > 0)
                {
                    BP.setblueprint(blueprint);
                    BP.Description.description = BP.Description.description + "\n" + message;
                    window.RenderBlueprint();
                }
            }
        }
コード例 #2
0
        private void button_render_Click(object sender, RoutedEventArgs e)
        {
            //string blueprintstr = blueprint.ToString();
            //string child = ((dynamic)filter_output.SelectedItem).child.ToString();
            Loadwindow w = new Loadwindow();

            try
            {
                w.Show();
                dynamic child = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(Edit_child.Text);
                int     i     = 0;
                int     index = ((dynamic)filter_output.SelectedItem).index;
                for (int j = 0; j < blueprint.bodies.Count; j++)
                {
                    for (int k = 0; k < blueprint.bodies[j].childs.Count; k++)
                    {
                        if (index == i)
                        {
                            blueprint.bodies[j].childs[k] = child;
                            BP.setblueprint(blueprint);
                            BP.Description.description = BP.Description.description + "\n++Applied RAW changes";
                            mainwindow.RenderBlueprint();
                            //Update();
                            w.Close();
                            MessageBox.Show("edit successful");

                            filterupdate();
                            return;
                        }
                        i++;
                    }
                }

                for (int j = 0; j < blueprint.joints.Count; j++)
                {
                    if (index == i)
                    {
                        blueprint.joints[j] = child;
                        BP.setblueprint(blueprint);
                        BP.Description.description = BP.Description.description + "\n++Applied RAW changes";
                        mainwindow.RenderBlueprint();
                        //Update();
                        w.Close();
                        MessageBox.Show("edit successful");
                        filterupdate();
                        return;
                    }
                    i++;
                }

                w.Close();
                MessageBox.Show("edit UNsuccessfull :(");
            }
            catch (Exception exc)
            {
                w.Close();
                MessageBox.Show(exc.Message);
            }
        }
コード例 #3
0
        private void Button_Create_Click(object sender, RoutedEventArgs e)
        {
            float X = Convert.ToInt32(TextBox_X.Text);
            float Y = Convert.ToInt32(TextBox_Y.Text);
            //float Z = Convert.ToInt32(TextBox_Z.Text);
            float t = 0.4f + (float)Convert.ToDouble(TextBox_thickness.Text);

            dynamic circle = new JObject();

            HashSet <Point3D> points = new HashSet <Point3D>();

            double precision = 0.95;
            double pp        = 0;

            for (float x = -X; x < X; x++)
            {
                for (float y = -Y; y < Y; y++)
                {
                    if ((Math.Pow(x / X, 2) + Math.Pow(y / Y, 2)) < precision &&
                        (Math.Pow((x) / (X - t), 2) + Math.Pow((y) / (Y - t), 2)) > (precision - pp))
                    {
                        points.Add(new Point3D(x, y, 1));
                    }
                }
            }


            circle = BlueprintOptimizer.CreateBlueprintFromPoints(points);


            if (circle.bodies[0].childs.Count > 0)
            {
                string  message       = "++ An ellipse/circle with " + circle.bodies[0].childs.Count + " shapes has been generated!";
                Random  r             = new Random();
                string  blueprintpath = Database.User_ + "\\Blueprints\\Generatedellipse-" + r.Next() + r.Next();
                dynamic description   = new JObject();
                description.description = "generated ellipsoid";
                description.name        = "generated ellipse/circle" + r.Next();
                description.type        = "Blueprint";
                description.version     = 0;

                if (BP.Blueprintpath == null)
                {//no blueprint exists, initialize new one
                    new BP(blueprintpath, circle, description);
                }
                else
                {//overwrite current blueprint
                    BP.setblueprint(circle);
                    BP.Description.description += message;
                }
                mainwindow.RenderBlueprint();
            }
            else
            {
                MessageBox.Show("no circle has been generated");
            }
        }
コード例 #4
0
        private void Click_mirrormode(object sender, RoutedEventArgs e)//needs work
        {
            dynamic blueprint = BP.Blueprint;

            if (blueprint.joints == null)
            {
                foreach (dynamic body in blueprint.bodies)
                {
                    foreach (dynamic block in body.childs)
                    {
                        {
                            dynamic realpos = BP.getposandbounds(block);

                            int xaxis = Convert.ToInt32(block.xaxis);
                            int zaxis = Convert.ToInt32(block.zaxis);
                            if (!((xaxis == 1 && zaxis == -2) || (Math.Abs(xaxis) == 1 && Math.Abs(zaxis) == 3) || (xaxis == -1 && zaxis == 2)))
                            {
                                realpos.xaxis = -xaxis;
                                realpos.zaxis = Math.Abs(zaxis) == 1? -zaxis : zaxis;
                            }
                            //Bounds bounds = Blockobject.BoundsByRotation(new Bounds(realpos.bounds),1,3);
                            realpos.pos.x = -Convert.ToInt32(block.pos.x) - ((realpos.pos.x == block.pos.x)? Convert.ToInt32(realpos.bounds.x) :0);
                            //realpos.pos.y = Convert.ToInt32(block.pos.y) - Convert.ToInt32(block.bounds.y);

                            block.pos   = BP.calcbppos(realpos).pos;
                            block.xaxis = BP.calcbppos(realpos).xaxis;
                            block.zaxis = BP.calcbppos(realpos).zaxis;

                            //block.pos.x = -Convert.ToInt32(block.pos.x);
                            //works thus far for blocks, not parts tho

                            /*
                             * if(Math.Abs(Convert.ToInt32(block.zaxis)) == 3 || Math.Abs(Convert.ToInt32(block.zaxis)) == 2)
                             * {
                             *  block.xaxis = -Convert.ToInt32(block.xaxis);
                             * }
                             * if(Math.Abs(Convert.ToInt32(block.zaxis)) == 1)
                             * {
                             *  block.zaxis = -Convert.ToInt32(block.zaxis);
                             * }*/
                            /*block.pos.x = -Convert.ToInt32(block.pos.x);
                            *  if(Convert.ToInt32(block.xaxis) == 1 || Convert.ToInt32(block.xaxis) == -1)
                            *   block.xaxis = -Convert.ToInt32(block.xaxis);
                            *  else
                            *   block.zaxis = -Convert.ToInt32(block.zaxis);*/
                        }
                    }
                }
                BP.setblueprint(blueprint);
                this.RenderBlueprint();
            }
            else
            {
                MessageBox.Show("Mirror mode can't mirror blueprints with joints inside yet!");
            }
            MessageBox.Show("Mirror mode did it's best to mirror things though there may be some parts that didn't turn out great.");
        }
コード例 #5
0
        private void Button_Create_Click(object sender, RoutedEventArgs e)
        {
            int thickness = Convert.ToInt32(TextBox_thickness.Text);
            int sizeX     = Convert.ToInt32(TextBox_X.Text);
            int sizeY     = Convert.ToInt32(TextBox_Y.Text);
            int sizeZ     = Convert.ToInt32(TextBox_Z.Text) - thickness;


            dynamic Cuboid = new JObject();

            Cuboid.bodies = new JArray();
            Cuboid.bodies.Add(new JObject());
            Cuboid.bodies[0].childs = new JArray();

            Cuboid.bodies[0].childs.Add(block(0, 0, 0, sizeX, sizeY, thickness));
            Cuboid.bodies[0].childs.Add(block(0, 0, thickness, sizeX, thickness, sizeZ));
            Cuboid.bodies[0].childs.Add(block(0, 0, thickness, thickness, sizeY, sizeZ));
            Cuboid.bodies[0].childs.Add(block(sizeX - thickness, thickness, thickness, thickness, sizeY - thickness, sizeZ - thickness));
            Cuboid.bodies[0].childs.Add(block(thickness, sizeY - thickness, thickness, sizeX - thickness, thickness, sizeZ - thickness));
            Cuboid.bodies[0].childs.Add(block(thickness, thickness, sizeZ, sizeX - thickness, sizeY - thickness, thickness));

            string  message      = "++ A Cuboid has been generated!";
            Random  r            = new Random();
            string  blueprintdir = Database.User_ + "\\Blueprints" + "\\GeneratedCuboid-" + r.Next() + r.Next();
            dynamic description  = new JObject();

            description.description = "generated cuboid";
            description.name        = "generated cuboid" + r.Next();
            description.type        = "Blueprint";
            description.version     = 0;

            if (BP.Blueprintpath == null)
            {//no blueprint exists, initialize new one
                new BP(blueprintdir, Cuboid, description);
            }
            else
            {//a blueprint exists, overwrite it
                BP.setblueprint(Cuboid);
                BP.Description.description += message;
            }
            mainWindow.RenderBlueprint();
        }
コード例 #6
0
        private void Click_fixcreation(object sender, RoutedEventArgs e)
        {
            dynamic blueprint = new JObject();

            blueprint.bodies  = new JArray();
            blueprint.version = 1;
            blueprint.bodies.Add(new JObject());
            blueprint.bodies[0].childs = new JArray();

            //BP.Blueprint.joints = null;
            foreach (dynamic body in BP.Blueprint.bodies)
            {
                //remove bearings/springs/pistons
                foreach (dynamic child in body.childs)
                {
                    if (child.joints != null)
                    {
                        child.joints = null;
                    }
                    if (child.controller != null)
                    {
                        if (child.controller.joints != null)
                        {
                            child.controller.joints = null;
                        }
                        if (child.controller.controllers != null)
                        {
                            child.controller.controllers = null;
                        }
                    }
                    blueprint.bodies[0].childs.Add(child);
                }
            }
            BP.Description.description = BP.Description.description + "\n++ removed joints & glitchwelded";
            BP.setblueprint(blueprint);
            this.RenderBlueprint();
        }
コード例 #7
0
        //Wire it!
        private void Button1_Click(object sender, RoutedEventArgs e)
        {//WIRE IT!
            if (comboBox_items1.SelectedIndex != -1 && comboBox_items2.SelectedIndex != -1 && BP.Blueprint != null)
            {
                dynamic     backupbp         = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(BP.Blueprint.ToString());
                string      sourcecolor      = textBox_color1.Text.ToLower();
                string      destinationcolor = textBox_color2.Text.ToLower();
                Connectable sourceblock      = (Connectable)comboBox_items1.SelectedItem;
                Connectable destinationblock = (Connectable)comboBox_items2.SelectedItem;

                int offsetx = Convert.ToInt32(textBox_X.Text);
                int offsety = Convert.ToInt32(textBox_Y.Text);
                int offsetz = Convert.ToInt32(textBox_Z.Text);

                if (sourcecolor.Length == 7)
                {
                    sourcecolor = sourcecolor.Substring(1, 6);
                }
                else
                {
                    sourcecolor = null;
                }
                if (destinationcolor.Length == 7)
                {
                    destinationcolor = destinationcolor.Substring(1, 6);
                }
                else
                {
                    destinationcolor = null;
                }
                //try
                {
                    WireIt(null, sourcecolor, destinationcolor, sourceblock.UUID, destinationblock.UUID, offsetx, offsety, offsetz, destinationcolor);
                }
                //catch (Exception ex)
                {
                    //  MessageBox.Show(ex.Message + "\n\n Blueprint connections abrupted\nrestoring blueprint", "ERROR");
                    //BP.setblueprint(backupbp);
                }

                if (false)
                {
                    #region oldcode
                    //list all destionationblocks and their ID's
                    dynamic destids = new JObject();
                    int     minx = 10000, maxx = -10000, miny = 10000, maxy = -10000, minz = 10000, maxz = -10000;
                    //loop over all blocks:
                    foreach (dynamic body in BP.Blueprint.bodies)
                    {
                        foreach (dynamic child in body.childs)
                        {
                            if (child.shapeId.Value.ToLower() == destinationblock.UUID.ToLower() /*&& (child.color.Value.ToLower() == destinationcolor.ToLower() || "#"+child.color.Value.ToLower() == destinationcolor.ToLower() || destinationcolor == "" || destinationcolor == "#")*/)
                            {
                                dynamic dest = BP.getposandbounds(child);//outputs corrected child (default rotation, correct position)

                                string x = dest.pos.x.ToString();
                                string y = dest.pos.y.ToString();
                                string z = dest.pos.z.ToString();

                                if (destids[x] == null)
                                {
                                    destids[x] = new JObject();
                                }
                                if (destids[x][y] == null)
                                {
                                    destids[x][y] = new JObject();
                                }
                                if (destids[x][y][z] == null)
                                {
                                    destids[x][y][z] = new JObject();
                                }
                                if (destids[x][y][z].ids == null)
                                {
                                    destids[x][y][z].ids = new JArray();
                                }
                                dynamic id = new JObject();
                                id.id = child.controller.id;
                                destids[x][y][z].ids.Add(id);
                                destids[x][y][z].color = child.color;

                                //get whole creation bounds:
                                if (dest.pos.x < minx)
                                {
                                    minx = dest.pos.x;
                                }
                                if (dest.pos.x > maxx)
                                {
                                    maxx = dest.pos.x;
                                }
                                if (dest.pos.y < miny)
                                {
                                    miny = dest.pos.y;
                                }
                                if (dest.pos.y > maxy)
                                {
                                    maxy = dest.pos.y;
                                }
                                if (dest.pos.z < minz)
                                {
                                    minz = dest.pos.z;
                                }
                                if (dest.pos.z > maxz)
                                {
                                    maxz = dest.pos.z;
                                }

                                /* {//test
                                 *   if (destids[x + "." + y + "." + z] == null) destids[x + "." + y + "." + z] = new JArray();
                                 *   dynamic blockproperties = new JObject();
                                 *   blockproperties.id = new JObject();
                                 *   blockproperties.id.id = child.controller.id;
                                 *   blockproperties.uuid = child.shapeId;
                                 *   if (child.color.ToString().StartsWith("#")) child.color = child.color.ToString().subString(1);
                                 *   blockproperties.color = child.color;
                                 *   destids[x + "." + y + "." + z].Add(blockproperties);
                                 * }*/
                            }
                        }
                    }
                    if (BP.Blueprint.joints != null)
                    {
                        foreach (dynamic child in BP.Blueprint.joints)
                        {
                            if (child.shapeId.Value.ToLower() == destinationblock.UUID.ToLower() /*&& (child.color.Value.ToLower() == destinationcolor.ToLower() || "#"+child.color.Value.ToLower() == destinationcolor.ToLower() || destinationcolor == "" || destinationcolor == "#")*/)
                            {
                                dynamic dest = (child);//outputs corrected child (default rotation, correct position)

                                string x = dest.pos.x.ToString();
                                string y = dest.pos.y.ToString();
                                string z = dest.pos.z.ToString();

                                if (destids[x] == null)
                                {
                                    destids[x] = new JObject();
                                }
                                if (destids[x][y] == null)
                                {
                                    destids[x][y] = new JObject();
                                }
                                if (destids[x][y][z] == null)
                                {
                                    destids[x][y][z] = new JObject();
                                }
                                if (destids[x][y][z].ids == null)
                                {
                                    destids[x][y][z].ids = new JArray();
                                }
                                dynamic id = new JObject();
                                id.id = child.controller.id;
                                destids[x][y][z].ids.Add(id);
                                destids[x][y][z].color = child.color;

                                //get whole creation bounds:
                                if (dest.pos.x < minx)
                                {
                                    minx = dest.pos.x;
                                }
                                if (dest.pos.x > maxx)
                                {
                                    maxx = dest.pos.x;
                                }
                                if (dest.pos.y < miny)
                                {
                                    miny = dest.pos.y;
                                }
                                if (dest.pos.y > maxy)
                                {
                                    maxy = dest.pos.y;
                                }
                                if (dest.pos.z < minz)
                                {
                                    minz = dest.pos.z;
                                }
                                if (dest.pos.z > maxz)
                                {
                                    maxz = dest.pos.z;
                                }
                            }
                        }
                    }

                    int amountwired = 0;
                    try
                    {
                        //can be improved!

                        foreach (dynamic body in BP.Blueprint.bodies)
                        {
                            foreach (dynamic child in body.childs)
                            {
                                if (child.shapeId.Value.ToLower() == sourceblock.UUID.ToLower() && (child.color.Value.ToLower() == sourcecolor.ToLower() || "#" + child.color.Value.ToLower() == sourcecolor.ToLower() || sourcecolor == "" || sourcecolor == "#"))
                                {                                               //COLOR AND UUID CORRECT, FURTHER WIRING PROCESS:
                                    dynamic source = BP.getposandbounds(child); //outputs corrected child (default rotation, correct position)

                                    string x = source.pos.x.ToString();
                                    string y = source.pos.y.ToString();
                                    string z = source.pos.z.ToString();

                                    if (checkBox_X.IsChecked == false)
                                    {
                                        minx = source.pos.x;
                                        maxx = source.pos.x;//bounds?
                                    }
                                    if (checkBox_Y.IsChecked == false)
                                    {
                                        miny = source.pos.y;
                                        maxy = source.pos.y;
                                    }
                                    if (checkBox_Z.IsChecked == false)
                                    {
                                        minz = source.pos.z;
                                        maxz = source.pos.z;
                                    }

                                    string color = child.color.ToString();
                                    if (color.StartsWith("#"))
                                    {
                                        color.Substring(1, 6);
                                    }
                                    for (int i = minx; i <= maxx; i++)
                                    {
                                        if (destids[i.ToString()] != null)
                                        {
                                            for (int j = miny; j <= maxy; j++)
                                            {
                                                if (destids[i.ToString()][j.ToString()] != null)
                                                {
                                                    for (int k = minz; k <= maxz; k++)
                                                    {
                                                        if (destids[i.ToString()][j.ToString()][k.ToString()] != null)
                                                        {
                                                            if (destids[i.ToString()][j.ToString()][k.ToString()].color.ToString().ToLower() == destinationcolor.ToLower() || "#" + destids[i.ToString()][j.ToString()][k.ToString()].color.ToString().ToLower() == destinationcolor.ToLower() || destinationcolor == "" || destinationcolor == "#")
                                                            {
                                                                if (destids[(i + Convert.ToInt32(textBox_X.Text)).ToString()] != null && destids[(i + Convert.ToInt32(textBox_X.Text)).ToString()][(j + Convert.ToInt32(textBox_Y.Text)).ToString()] != null && destids[(i + Convert.ToInt32(textBox_X.Text)).ToString()][(j + Convert.ToInt32(textBox_Y.Text)).ToString()][(k + Convert.ToInt32(textBox_Z.Text)).ToString()] != null)
                                                                {
                                                                    foreach (dynamic id in destids[(i + Convert.ToInt32(textBox_X.Text)).ToString()][(j + Convert.ToInt32(textBox_Y.Text)).ToString()][(k + Convert.ToInt32(textBox_Z.Text)).ToString()].ids)
                                                                    {
                                                                        if (!(checkBox_0.IsChecked == false && child.controller.id == id.id))
                                                                        {
                                                                            if (child.controller.controllers == null)
                                                                            {
                                                                                child.controller.controllers = new JArray();
                                                                            }
                                                                            child.controller.controllers.Add(id);
                                                                            amountwired++;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    /*
                                     * for (int i = minx; i <= maxx; i++)
                                     *  for (int j = miny; j <= maxy; j++)
                                     *      for (int k = minz; k <= maxz; k++)
                                     *          if (
                                     *              destids[i.ToString() + "." + j.ToString() + "." + k.ToString()] != null &&
                                     *              destids[(i + Convert.ToInt32(textBox_X.Text)).ToString() + "." +
                                     *                      (j + Convert.ToInt32(textBox_Y.Text)).ToString() + "." +
                                     *                      (k + Convert.ToInt32(textBox_Z.Text)).ToString()] != null
                                     *              )
                                     *              foreach ( dynamic destblocknooffset in destids[i.ToString() + "." + j.ToString() + "." + k.ToString()])
                                     *                  if((destblocknooffset.color.ToLower() == destinationcolor.ToLower() || destinationcolor == "" || destinationcolor == "#"))
                                     *                      foreach(dynamic blockoffset in destids[(i + Convert.ToInt32(textBox_X.Text)).ToString() + "." + (j + Convert.ToInt32(textBox_Y.Text)).ToString() + "." + (k + Convert.ToInt32(textBox_Z.Text)).ToString()])
                                     *                          if(!(checkBox_0.IsChecked == false && child.controller.id == blockoffset.id.id))
                                     *                          {
                                     *                              if (child.controller.controllers == null)
                                     *                                  child.controller.controllers = new JArray();
                                     *                              child.controller.controllers.Add(blockoffset.id);
                                     *                              amountwired++;
                                     *                          }
                                     */

                                    mainwindow.Image_blueprint.DataContext = null;
                                    mainwindow.Image_blueprint.DataContext = mainwindow;
                                }
                            }
                        }

                        new System.Threading.Thread(new System.Threading.ThreadStart(() => {
                            if (Properties.Settings.Default.wires)
                            {
                                MessageBox.Show("Successfully made " + amountwired + " connections! :D\n\n'Wires'-feature will render wires upon load from openwindow->needs work");
                            }
                            else
                            {
                                MessageBox.Show("Successfully made " + amountwired + " connections! :D");
                            }
                        })).Start();

                        //window.UpdateOpenedBlueprint();
                        if (amountwired > 0)
                        {
                            BP.Description.description = BP.Description.description + "\n--> " + amountwired + " connections made between " + sourcecolor + " " + sourceblock.name + " and " + destinationcolor + " " + destinationblock.name;
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message + "\n\n Blueprint connections abrupted\nrestoring blueprint", "ERROR");
                        BP.setblueprint(backupbp);
                    }
                    #endregion
                }
            }
            else
            {
                MessageBox.Show("Something went wrong!\nno harm done");
            }
        }
コード例 #8
0
        private void button_render_Click(object sender, RoutedEventArgs e)
        {
            //apply changes
            if (Convert.ToInt32(filter_x1.Text) > Convert.ToInt32(filter_x2.Text))
            {
                string h = filter_x1.Text;
                filter_x1.Text = filter_x2.Text;
                filter_x2.Text = h;
            }
            if (Convert.ToInt32(filter_y1.Text) > Convert.ToInt32(filter_y2.Text))
            {
                string h = filter_y1.Text;
                filter_y1.Text = filter_y2.Text;
                filter_y2.Text = h;
            }
            if (Convert.ToInt32(filter_z1.Text) > Convert.ToInt32(filter_z2.Text))
            {
                string h = filter_z1.Text;
                filter_z1.Text = filter_z2.Text;
                filter_z2.Text = h;
            }
            int    x1         = Convert.ToInt32(filter_x1.Text);
            int    y1         = Convert.ToInt32(filter_y1.Text);
            int    z1         = Convert.ToInt32(filter_z1.Text);
            int    x2         = Convert.ToInt32(filter_x2.Text);
            int    y2         = Convert.ToInt32(filter_y2.Text);
            int    z2         = Convert.ToInt32(filter_z2.Text);
            string targetuuid = null;

            if (filter_type.SelectedIndex < 0)
            {
                filter_type.SelectedIndex = 0;
            }
            if (filter_type.SelectedIndex > 0)
            {
                targetuuid = ((Item)filter_type.SelectedItem).UUID;
            }


            dynamic blueprint = BP.Blueprint;

            if (filtercolor != null && filtercolor.StartsWith("#"))
            {
                filtercolor = filtercolor.Substring(1, 6).ToLower();
            }

            foreach (dynamic body in blueprint.bodies)
            {
                foreach (dynamic child in body.childs)
                {
                    if (child.color.ToString().StartsWith("#"))
                    {
                        child.color = child.color.ToString().Substring(1, 6).ToLower();
                    }
                    dynamic realpos = BP.getposandbounds(child);
                    if ((filtercolor == null || filtercolor == child.color.ToString()) &&
                        (targetuuid == null || targetuuid == child.shapeId.ToString()) &&
                        (x1 <= (int)realpos.pos.x && (int)realpos.pos.x + (int)realpos.bounds.x <= x2) &&
                        (y1 <= (int)realpos.pos.y && (int)realpos.pos.y + (int)realpos.bounds.y <= y2) &&
                        (z1 <= (int)realpos.pos.z && (int)realpos.pos.z + (int)realpos.bounds.z <= z2))
                    {
                        child.pos.x = child.pos.x + Convert.ToInt32(new_x.Text);
                        child.pos.y = child.pos.y + Convert.ToInt32(new_y.Text);
                        child.pos.z = child.pos.z + Convert.ToInt32(new_z.Text);

                        if (new_color.Text != "")
                        {
                            child.color = new_color.Text.ToString().Substring(1, 6);
                        }
                        if (Edit_gate.IsVisible && new_gatemode.SelectedIndex > 0)
                        {
                            child.controller.mode = new_gatemode.SelectedIndex - 1;
                        }
                        if (Edit_lamp.IsVisible)
                        {
                            if (new_luminance.Text != "")
                            {
                                child.controller.luminance = Convert.ToInt32(new_luminance.Text);
                            }
                            if (new_coneangle.Text != "")
                            {
                                child.controller.coneAngle = Convert.ToInt32(new_coneangle.Text);
                            }
                            if (new_lampcolor.Text != "")
                            {
                                child.controller.color = new_lampcolor.Text;
                            }
                        }
                        if (Edit_sensor.IsVisible && (new_sensorrange.Text != "" || new_sensorcolormode.IsChecked == true))
                        {
                            if (new_sensorrange.Text != "")
                            {
                                child.controller.range = Convert.ToInt32(new_sensorrange.Text);
                            }

                            child.controller.colorMode = new_sensorcolormode.IsChecked == true?true:false;
                            child.controller.color     = new_sensorcolor.Text;
                        }
                        if (Edit_Timer.IsVisible && new_timerseconds.Text != null)
                        {
                            child.controller.seconds = Convert.ToInt32(new_timerseconds);
                            child.controller.ticks   = Convert.ToInt32(new_timerticks);
                        }
                    }
                }
            }
            if (blueprint.joints != null)
            {
                foreach (dynamic child in blueprint.joints)
                {
                    if (child.color.ToString().StartsWith("#"))
                    {
                        child.color = child.color.ToString().Substring(1, 6);
                    }
                    dynamic c = child;
                    c.pos   = child.posA;
                    c.xaxis = child.xaxisA;
                    c.zaxis = child.zaxisA;
                    dynamic realpos = BP.getposandbounds(c);
                    realpos.pos = child.posA;
                    if (!(Convert.ToInt32(child.zaxis.ToString()) > 0 || !(realpos.bounds.x != 1 || realpos.bounds.y != 1 || realpos.bounds.z != 1)))
                    {
                        int zaxis = Convert.ToInt32(child.zaxis.ToString());
                        if (zaxis == -1)
                        {
                            realpos.pos.x -= realpos.bounds.x - 1;
                        }
                        if (zaxis == -2)
                        {
                            realpos.pos.y -= realpos.bounds.y - 1;
                        }
                        if (zaxis == -3)
                        {
                            realpos.pos.z -= realpos.bounds.z - 1;
                        }
                    }

                    if ((filtercolor == null || filtercolor == child.color.ToString()) &&
                        (targetuuid == null || targetuuid == child.shapeId.ToString()) &&
                        (x1 <= (int)realpos.pos.x && (int)realpos.pos.x + (int)realpos.bounds.x <= x2) &&
                        (y1 <= (int)realpos.pos.y && (int)realpos.pos.y + (int)realpos.bounds.y <= y2) &&
                        (z1 <= (int)realpos.pos.z && (int)realpos.pos.z + (int)realpos.bounds.z <= z2))
                    {
                        child.posA.x = child.posA.x + Convert.ToInt32(new_x.Text);
                        child.posA.y = child.posA.y + Convert.ToInt32(new_y.Text);
                        child.posA.z = child.posA.z + Convert.ToInt32(new_z.Text);
                        if (new_color.Text != "")
                        {
                            child.color = new_color.Text.ToString().Substring(1, 6);
                        }
                    }
                }
            }


            Loadwindow w = new Loadwindow();

            w.Show();
            BP.Description.description = BP.Description.description += "++ Applied some area property changes ";
            BP.setblueprint(BP.Blueprint);
            this.mainwindow.RenderBlueprint();
            //Update();
            filterupdate();
            w.Close();
        }
コード例 #9
0
        private void Convertobj(object sender, DoWorkEventArgs e)
        {
            Scene scene = new AssimpImporter().ImportFile(file, PostProcessSteps.Triangulate);

            //List<Triangle> splittriangles = new List<Triangle>();
            pointlist = new HashSet <Point3D>();
            //pointlist.ToDictionary<>
            int progress = 0;
            int total    = 0;

            try
            {
                foreach (Mesh m in scene.Meshes)
                {
                    foreach (Face face in m.Faces)
                    {
                        total++;
                    }
                }
                foreach (Mesh m in scene.Meshes)
                {
                    foreach (Face face in m.Faces)
                    {
                        IList <Point3D> vertices = new List <Point3D>();
                        foreach (uint i in face.Indices)
                        {
                            double  x = m.Vertices[i].X * scale;
                            double  y = m.Vertices[i].Y * scale;
                            double  z = m.Vertices[i].Z * scale;
                            Point3D point;
                            if (flipyz)
                            {
                                if (flipxz)
                                {
                                    point = new Point3D(y, z, flipz * x);
                                }
                                else
                                {
                                    point = new Point3D(x, z, flipz * y);
                                }
                            }
                            else
                            {
                                if (flipxz)
                                {
                                    point = new Point3D(z, y, flipz * x);
                                }
                                else
                                {
                                    point = new Point3D(x, y, flipz * z);
                                }
                            }
                            vertices.Add(point);
                            pointlist.Add(new Point3D((int)Math.Floor(point.X), (int)Math.Floor(point.Y), (int)Math.Floor(point.Z)));
                        }
                        if (vertices.Count == 3)
                        {
                            Triangle triangle = new Triangle(vertices);
                            if (!triangle.BoundsSmallerThan(bounds))
                            {
                                Splittriangles(triangle);
                            }
                        }
                        else
                        {
                        }
                        progress++;
                        backgroundWorker.ReportProgress((progress * 100) / total);
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (!(ex is OperationCanceledException))
                {
                    System.Windows.MessageBox.Show(ex.Message, "Something went wrong converting the obj");
                }
                else
                {
                    e.Cancel = true;
                }
            }

            try
            {
                if (backgroundWorker.CancellationPending)
                {
                    throw new OperationCanceledException();
                }

                dynamic blueprint = new JObject();
                try
                {
                    blueprint = BlueprintOptimizer.CreateBlueprintFromPoints(pointlist);
                }
                catch (Exception bpex)
                {
                    System.Windows.MessageBox.Show(bpex.Message, "Something went wrong building the blueprint");
                }
                int    amountgenerated = blueprint.bodies[0].childs.Count;
                string message         = "converted obj to blueprint with " + amountgenerated + " blocks !";
                //MessageBox.Show(message+"\n\nOptimized to: "+count+" shapes");
                Random  r             = new Random();
                string  blueprintpath = Database.User_ + "\\Blueprints\\Generatedblueprintobj-" + r.Next() + r.Next();
                dynamic description   = new JObject();
                description.description = "generated obj blueprint with " + amountgenerated + " block";
                description.name        = "generated blueprint" + r.Next();
                description.type        = "Blueprint";
                description.version     = 0;
                new Task(() =>
                {
                    System.Windows.MessageBox.Show(message + "\nPLEASE WAIT for the rendering to complete");
                }).Start();
                if (BP.Blueprintpath == null)
                {//no blueprint exists, initialize new one
                    new BP(blueprintpath, blueprint, description);
                }
                else
                {//overwrite current blueprint
                    BP.setblueprint(blueprint);
                    BP.Description.description += message;
                }
            }
            catch (Exception exc)
            {
                System.Windows.MessageBox.Show(exc.Message, "error");
            }
        }
コード例 #10
0
        private void Convertobjwtexture(object sender, DoWorkEventArgs e)
        {
            try
            {
                Scene scene = new AssimpImporter().ImportFile(file, PostProcessSteps.Triangulate);

                coloredpoints = new Dictionary <Point3D, Point3D>();
                //List<Triangle> splittriangles = new List<Triangle>();
                //pointlist = new HashSet<Point3D>();


                //pointlist.ToDictionary<>
                int progress = 0;
                int total    = 0;

                foreach (Mesh m in scene.Meshes)
                {
                    foreach (Face face in m.Faces)
                    {
                        total++;
                    }
                }
                foreach (Mesh m in scene.Meshes)
                {
                    var texturecoords = m.GetTextureCoords(0);

                    foreach (Face face in m.Faces)
                    {
                        IList <Point3D> vertices      = new List <Point3D>();
                        IList <Point3D> texturepoints = new List <Point3D>();
                        foreach (uint i in face.Indices)
                        {
                            double          x = m.Vertices[i].X * scale;
                            double          y = m.Vertices[i].Y * scale;
                            double          z = m.Vertices[i].Z * scale;
                            Point3D         point;
                            Assimp.Vector3D texturep     = texturecoords[i];
                            Point3D         texturepoint = new Point3D(texturep.X, 1 - texturep.Y, texturep.Z);
                            if (flipyz)
                            {
                                if (flipxz)
                                {
                                    point = new Point3D(y, z, flipz * x);
                                }
                                else
                                {
                                    point = new Point3D(x, z, flipz * y);
                                }
                            }
                            else
                            {
                                if (flipxz)
                                {
                                    point = new Point3D(z, y, flipz * x);
                                }
                                else
                                {
                                    point = new Point3D(x, y, flipz * z);
                                }
                            }
                            vertices.Add(point);
                            texturepoints.Add(texturepoint);
                            Point3D flooredpoint = new Point3D((int)Math.Floor(point.X), (int)Math.Floor(point.Y), (int)Math.Floor(point.Z));
                            if (!coloredpoints.ContainsKey(flooredpoint))
                            {
                                coloredpoints.Add(flooredpoint, texturepoint);
                            }
                        }
                        if (vertices.Count == 3)
                        {
                            ColorTriangle triangle = new ColorTriangle(vertices, texturepoints);
                            if (!triangle.BoundsSmallerThan(bounds))
                            {
                                Splitcolortriangles(triangle);
                            }
                        }
                        else
                        {
                        }
                        progress++;
                        backgroundWorker.ReportProgress((progress * 100) / total);
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (!(ex is OperationCanceledException))
                {
                    System.Windows.MessageBox.Show(ex.Message, "Something went wrong converting the obj+texture");
                }
                else
                {
                    e.Cancel = true;
                }
            }

            try
            {
                if (backgroundWorker.CancellationPending)
                {
                    throw new OperationCanceledException();
                }

                dynamic blueprint = new JObject();
                try
                {
                    Bitmap texturemap = new Bitmap(this.texture);
                    HashSet <Tuple <Point3D, string> > pointswithcolor = new HashSet <Tuple <Point3D, string> >();
                    int width  = texturemap.Width;
                    int height = texturemap.Height;
                    foreach (var pair in coloredpoints)
                    {
                        int x = (int)(pair.Value.X * width);
                        int y = (int)(pair.Value.Y * height);
                        if (pair.Value.Y > 1)
                        {
                        }
                        while (y < 0)
                        {
                            y++;
                        }
                        while (x < 0)
                        {
                            x++;
                        }
                        if (Math.Abs(x) > width / 2)
                        {
                        }
                        while (x >= width)
                        {
                            x -= width;
                        }
                        while (y >= height)
                        {
                            y -= height;
                        }
                        System.Drawing.Color color = texturemap.GetPixel(x, y);
                        string c = color.Name.Substring(2);
                        pointswithcolor.Add(new Tuple <Point3D, string>(pair.Key, c));
                    }
                    coloredpoints.Clear();
                    blueprint = BlueprintOptimizer.CreateBlueprintFromPointsAndColor(pointswithcolor);
                }
                catch (Exception bpex)
                {
                    System.Windows.MessageBox.Show(bpex.Message, "Something went wrong building the blueprint");
                }
                int    amountgenerated = blueprint.bodies[0].childs.Count;
                string message         = "converted obj to blueprint with " + amountgenerated + " blocks !";
                //MessageBox.Show(message+"\n\nOptimized to: "+count+" shapes");
                Random  r             = new Random();
                string  blueprintpath = Database.User_ + "\\Blueprints\\Generatedblueprintobj-" + r.Next() + r.Next();
                dynamic description   = new JObject();
                description.description = "generated obj blueprint with " + amountgenerated + " block";
                description.name        = "generated blueprint" + r.Next();
                description.type        = "Blueprint";
                description.version     = 0;
                new Task(() =>
                {
                    System.Windows.MessageBox.Show(message + "\nPLEASE WAIT for the rendering to complete");
                }).Start();
                if (BP.Blueprintpath == null)
                {//no blueprint exists, initialize new one
                    new BP(blueprintpath, blueprint, description);
                }
                else
                {//overwrite current blueprint
                    BP.setblueprint(blueprint);
                    BP.Description.description += message;
                }
            }
            catch (Exception exc)
            {
                System.Windows.MessageBox.Show(exc.Message, "error");
            }
        }
コード例 #11
0
        private void button_render_Click(object sender, RoutedEventArgs e)
        {
            //blueprintIndex
            foreach (dynamic body in BP.Blueprint.bodies)
            {
                foreach (dynamic child in body.childs)
                {
                    if (Convert.ToInt32(child.blueprintIndex) == selectedchildindex)
                    {
                        if (Edit_controller.IsVisible)
                        {
                            child.controller.joints.Clear();
                            foreach (dynamic item in (dynamic)new_controllercontrolls.Items)
                            {
                                item.startAngle            = Convert.ToInt32(item.startAngle);
                                item.frames[0].targetAngle = Convert.ToInt32(item.controller0);
                                item.frames[1].targetAngle = Convert.ToInt32(item.controller1);
                                item.frames[2].targetAngle = Convert.ToInt32(item.controller2);
                                item.frames[3].targetAngle = Convert.ToInt32(item.controller3);
                                item.frames[4].targetAngle = Convert.ToInt32(item.controller4);
                                item.frames[5].targetAngle = Convert.ToInt32(item.controller5);
                                item.frames[6].targetAngle = Convert.ToInt32(item.controller6);
                                item.frames[7].targetAngle = Convert.ToInt32(item.controller7);
                                item.frames[8].targetAngle = Convert.ToInt32(item.controller8);
                                item.frames[9].targetAngle = Convert.ToInt32(item.controller9);
                                child.controller.joints.Add(item);
                            }
                        }
                        if (Edit_gate.IsVisible)
                        {
                            child.controller.mode = new_gatemode.SelectedIndex;
                        }
                        if (Edit_general.IsVisible)
                        {
                            child.pos.x = Convert.ToInt32(new_x.Text);
                            child.pos.y = Convert.ToInt32(new_y.Text);
                            child.pos.z = Convert.ToInt32(new_z.Text);
                            child.color = new_color.Text;
                            child.xaxis = Convert.ToInt32(new_xaxis.Text);
                            child.zaxis = Convert.ToInt32(new_zaxis.Text);

                            dynamic selectedblock = ((dynamic)filter_output.SelectedItem);
                            selectedblock.pos.x = child.pos.x;
                            selectedblock.pos.y = child.pos.y;
                            selectedblock.pos.z = child.pos.z;
                            selectedblock.xaxis = child.xaxis;
                            selectedblock.zaxis = child.zaxis;
                        }
                        if (Edit_sensor.IsVisible)
                        {
                            child.controller.colorMode = new_sensorcolormode.IsChecked;
                            child.controller.range     = Convert.ToInt32(new_sensorrange.Text);
                            child.controller.color     = new_sensorcolor.Text;
                        }
                        if (Edit_lamp.IsVisible)
                        {
                            child.controller.coneAngle = Convert.ToInt32(new_coneangle.Text);
                            child.controller.luminance = Convert.ToInt32(new_luminance.Text);
                        }
                        if (Edit_Timer.IsVisible)
                        {
                            child.controller.seconds = Convert.ToInt32(new_timerseconds.Text);
                            child.controller.ticks   = Convert.ToInt32(new_timerticks.Text);
                        }
                    }
                }
            }


            Loadwindow w = new Loadwindow();

            w.Show();

            BP.Description.description = BP.Description.description += "++ Applied some block property changes ";
            BP.setblueprint(BP.Blueprint);
            this.mainwindow.RenderBlueprint();
            //Update();
            dynamic bounds = BP.GetBounds();
            int     x1 = bounds.minx, y1 = bounds.maxx, z1 = bounds.miny, x2 = bounds.maxy, y2 = bounds.minz, z2 = bounds.maxz;

            this.Dispatcher.Invoke((Action)(() =>
            {//this refer to form in WPF application
                if (filter_x1.Text != "")
                {
                    x1 = Convert.ToInt32(filter_x1.Text);
                }
                if (filter_y1.Text != "")
                {
                    y1 = Convert.ToInt32(filter_y1.Text);
                }
                if (filter_z1.Text != "")
                {
                    z1 = Convert.ToInt32(filter_z1.Text);
                }
                if (filter_x2.Text != "")
                {
                    x2 = Convert.ToInt32(filter_x2.Text);
                }
                if (filter_y2.Text != "")
                {
                    y2 = Convert.ToInt32(filter_y2.Text);
                }
                if (filter_z2.Text != "")
                {
                    z2 = Convert.ToInt32(filter_z2.Text);                      //0.1! = any
                }
                this.mainwindow.setMarker2((x1 + x2 + 0.0f) / 2, (y1 + y2 + 0.0f) / 2, (z1 + z2 + 0.0f) / 2, (x2 - x1), (y2 - y1), (z2 - z1));
            }));
            w.Close();
        }
コード例 #12
0
        private void Button_Create_Click(object sender, RoutedEventArgs e)
        {
            float X = Convert.ToInt32(TextBox_X.Text);
            float Y = Convert.ToInt32(TextBox_Y.Text);
            float Z = Convert.ToInt32(TextBox_Z.Text);
            float t = Convert.ToInt32(TextBox_thickness.Text);

            dynamic Sphere = new JObject();

            Sphere.bodies = new JArray();
            Sphere.bodies.Add(new JObject() as dynamic);
            Sphere.bodies[0].childs = new JArray();

            dynamic blocksXYZ       = new JObject();
            int     amountgenerated = 0;

            for (float x = -X; x < X; x++)
            {
                for (float y = -Y; y < Y; y++)
                {
                    for (float z = -Z; z < Z; z++)
                    {
                        if ((Math.Pow(x / X, 2) + Math.Pow(y / Y, 2) + Math.Pow(z / Z, 2)) < 0.95 &&
                            (Math.Pow(x / (X - t), 2) + Math.Pow((y) / (Y - t), 2) + Math.Pow(z / (Z - t), 2)) > 0.95)
                        {
                            if (blocksXYZ[x.ToString()] == null)
                            {
                                blocksXYZ[x.ToString()] = new JObject();
                            }
                            if (blocksXYZ[x.ToString()][y.ToString()] == null)
                            {
                                blocksXYZ[x.ToString()][y.ToString()] = new JObject();
                            }
                            if (blocksXYZ[x.ToString()][y.ToString()][z.ToString()] == null)
                            {
                                blocksXYZ[x.ToString()][y.ToString()][z.ToString()] = new JObject();
                            }
                            dynamic bounds = new JObject();
                            bounds.x = 1;
                            bounds.y = 1;
                            bounds.z = 1;
                            blocksXYZ[x.ToString()][y.ToString()][z.ToString()].bounds = bounds;
                            amountgenerated++;
                        }
                    }
                }
            }

            foreach (dynamic x in blocksXYZ)
            {
                foreach (dynamic y in x.Value)
                {
                    foreach (dynamic z in y.Value)
                    {
                        dynamic bounds = z.Value.bounds;
                        if (bounds != null)
                        {
                            for (int i = Convert.ToInt32(z.Name) + 1; i < 64; i++)
                            {
                                if (blocksXYZ[x.Name][y.Name][i.ToString()] != null && blocksXYZ[x.Name][y.Name][i.ToString()].bounds != null)
                                {
                                    blocksXYZ[x.Name][y.Name][i.ToString()].bounds = null;

                                    blocksXYZ[x.Name][y.Name][z.Name].bounds.z = Convert.ToInt32(blocksXYZ[x.Name][y.Name][z.Name].bounds.z) + 1;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            foreach (dynamic x in blocksXYZ)
            {
                foreach (dynamic y in x.Value)
                {
                    foreach (dynamic z in y.Value)
                    {
                        dynamic bounds = z.Value.bounds;
                        if (bounds != null)
                        {
                            for (int i = Convert.ToInt32(y.Name) + 1; i < 64; i++)
                            {
                                if (blocksXYZ[x.Name][i.ToString()] != null && blocksXYZ[x.Name][i.ToString()][z.Name] != null &&
                                    blocksXYZ[x.Name][i.ToString()][z.Name].bounds != null &&
                                    blocksXYZ[x.Name][i.ToString()][z.Name].bounds.z == blocksXYZ[x.Name][y.Name][z.Name].bounds.z)
                                {
                                    blocksXYZ[x.Name][i.ToString()][z.Name].bounds = null;

                                    blocksXYZ[x.Name][y.Name][z.Name].bounds.y = Convert.ToInt32(blocksXYZ[x.Name][y.Name][z.Name].bounds.y) + 1;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            foreach (dynamic x in blocksXYZ)
            {
                foreach (dynamic y in x.Value)
                {
                    foreach (dynamic z in y.Value)
                    {
                        dynamic bounds = z.Value.bounds;
                        if (bounds != null)
                        {
                            for (int i = Convert.ToInt32(x.Name) + 1; i < 64; i++)
                            {
                                if (blocksXYZ[i.ToString()] != null && blocksXYZ[i.ToString()][y.Name] != null && blocksXYZ[i.ToString()][y.Name][z.Name] != null &&
                                    blocksXYZ[i.ToString()][y.Name][z.Name].bounds != null &&
                                    blocksXYZ[i.ToString()][y.Name][z.Name].bounds.z == blocksXYZ[x.Name][y.Name][z.Name].bounds.z &&
                                    blocksXYZ[i.ToString()][y.Name][z.Name].bounds.y == blocksXYZ[x.Name][y.Name][z.Name].bounds.y)
                                {
                                    blocksXYZ[i.ToString()][y.Name][z.Name].bounds = null;

                                    blocksXYZ[x.Name][y.Name][z.Name].bounds.x = Convert.ToInt32(blocksXYZ[x.Name][y.Name][z.Name].bounds.x) + 1;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }


            foreach (dynamic x in blocksXYZ)
            {
                foreach (dynamic y in x.Value)
                {
                    foreach (dynamic z in y.Value)
                    {
                        if (z.Value.bounds != null)
                        {
                            Sphere.bodies[0].childs.Add(block(Convert.ToInt32(x.Name), Convert.ToInt32(y.Name), Convert.ToInt32(z.Name), z.Value.bounds));
                        }
                    }
                }
            }

            if (amountgenerated > 0)
            {
                string message = "++ An ellipsoid with " + amountgenerated + " blocks has been generated!";
                //MessageBox.Show(message+"\n\nOptimized to: "+count+" shapes");
                Random  r             = new Random();
                string  blueprintpath = Database.User_ + "\\Blueprints\\GeneratedEllipsoid-" + r.Next() + r.Next();
                dynamic description   = new JObject();
                description.description = "generated ellipsoid";
                description.name        = "generated sphere" + r.Next();
                description.type        = "Blueprint";
                description.version     = 0;

                if (BP.Blueprintpath == null)
                {//no blueprint exists, initialize new one
                    new BP(blueprintpath, Sphere, description);
                }
                else
                {//overwrite current blueprint
                    BP.setblueprint(Sphere);
                    BP.Description.description += message;
                }
                mainwindow.RenderBlueprint();
            }
            else
            {
                MessageBox.Show("no ellipsoid has been generated");
            }
        }
コード例 #13
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TextBox t1       = (TextBox)textBox_color1;
            Brush   b        = t1.Background;
            string  oldcolor = "#" + (b as SolidColorBrush).Color.ToString().Substring(3);

            TextBox t2       = (TextBox)textBox_color2;
            Brush   b1       = t2.Background;
            string  newcolor = "#" + (b1 as SolidColorBrush).Color.ToString().Substring(3);

            int amountcolored = 0;

            foreach (dynamic body in BP.Blueprint.bodies)
            {
                foreach (dynamic child in body.childs)
                {
                    string token = "#";
                    string color = child.color.ToString();
                    if (color[0] == '#')
                    {
                        token = "";
                    }
                    if ((token + child.color.ToString().ToLower() == oldcolor.ToLower() || textBox_color1.Text == "#" || textBox_color1.Text == "") && ((comboBox_old.SelectedIndex <= 0) || child.shapeId.ToString() == ((Item)comboBox_old.SelectedItem).UUID.ToLower()))
                    {
                        amountcolored++;
                        child.color = newcolor;
                    }
                }
            }
            if (BP.Blueprint.joints != null)
            {
                foreach (dynamic child in BP.Blueprint.joints)
                {
                    string token = "#";
                    string color = child.color.ToString();
                    if (color[0] == '#')
                    {
                        token = "";
                    }
                    if ((token + child.color.ToString().ToLower() == oldcolor.ToLower() || textBox_color1.Text == "#" || textBox_color1.Text == "") && ((comboBox_old.SelectedIndex <= 0) || child.shapeId.ToString() == ((Item)comboBox_old.SelectedItem).UUID.ToLower()))
                    {
                        amountcolored++;
                        child.color = newcolor.Substring(1);
                    }
                }
            }
            if (comboBox_old.SelectedIndex < 0)
            {
                comboBox_old.SelectedIndex = 0;
            }
            string message = "++ " + amountcolored + " " + oldcolor + " " + ((Item)comboBox_old.SelectedItem).Name + " are now painted " + newcolor + " color";

            if (textBox_color1.Text == "#" || textBox_color1.Text == "")
            {
                message = "++ " + amountcolored + ((Item)comboBox_old.SelectedItem).Name + " are now painted " + newcolor + " color";
            }

            new System.Threading.Thread(new System.Threading.ThreadStart(() => { MessageBox.Show(message); })).Start();

            if (amountcolored > 0)
            {
                BP.setblueprint(BP.Blueprint);

                BP.Description.description = BP.Description.description + "\n" + message;
                window.RenderBlueprint();
            }
        }