コード例 #1
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.");
        }
コード例 #2
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");
            }
        }
コード例 #3
0
        private void WireIt(dynamic a, string sourcecolor, string destinationcolor, string sourcetype, string destinationtype, int offsetx, int offsety, int offsetz, string offsetcolor)
        {
            Dictionary <int, Controller> controllers = new Dictionary <int, Controller>();
            bool dirx        = checkBox_X.IsChecked == true;
            bool diry        = checkBox_Y.IsChecked == true;
            bool dirz        = checkBox_Z.IsChecked == true;
            bool self        = checkBox_0.IsChecked == true;
            bool matchoffset = MatchOffset.IsChecked == true;                                     //safemode enable?

            Dictionary <string, List <int> > filtercrap = new Dictionary <string, List <int> >(); //can be glitchwelded

            //x.y.z = int

            foreach (dynamic body in BP.Blueprint.bodies)
            {
                foreach (dynamic child in body.childs)
                {
                    if (child.controller != null)
                    {
                        dynamic rpos  = BP.getposandbounds(child);
                        int     x     = Convert.ToInt32(rpos.pos.x.ToString());
                        int     y     = Convert.ToInt32(rpos.pos.y.ToString());
                        int     z     = Convert.ToInt32(rpos.pos.z.ToString());
                        string  color = child.color.ToString().ToLower();
                        if (color.StartsWith("#"))
                        {
                            color = color.Substring(1, 6);
                        }
                        int id = Convert.ToInt32(child.controller.id.ToString());
                        controllers.Add(id, new Controller {
                            id = id, x = x, y = y, z = z, color = color, uuid = child.shapeId.ToString(), connections = new List <int>()
                        });

                        string key = x.ToString() + "." + y.ToString() + "." + z.ToString();
                        if (!filtercrap.ContainsKey(key))
                        {
                            filtercrap.Add(key, new List <int> {
                                id
                            });
                        }
                        else
                        {
                            filtercrap[key].Add(id);
                        }
                    }
                }
            }

            if (matchoffset)
            {//filter only the block with color,type,offset from source
                foreach (Controller source in controllers.Values)
                {
                    if ((sourcecolor == null || sourcecolor == source.color) && (sourcetype == source.uuid))
                    {
                        foreach (Controller destination in controllers.Values)
                        {
                            if ((destinationcolor == null || destinationcolor == destination.color) && (destinationtype == null || destinationtype == destination.uuid) &&
                                (self || !source.Equals(destination)) &&
                                (dirx || source.x + offsetx == destination.x) && (diry || source.y + offsety == destination.y) && (dirz || source.z + offsetz == destination.z))
                            {
                                source.connections.Add(destination.id);
                            }
                        }
                    }
                }
            }
            else//filter all blocks no offset with col&type, then get the ones offset from them (any color, any type)
            {
                foreach (Controller source in controllers.Values)
                {
                    if ((sourcecolor == null || sourcecolor == source.color) && (sourcetype == source.uuid))
                    {
                        foreach (Controller destination in controllers.Values)
                        {
                            if ((destinationcolor == null || destinationcolor == destination.color) && (destinationtype == null || destinationtype == destination.uuid) &&
                                (self || !source.Equals(destination)) &&
                                (dirx || source.x == destination.x) && (diry || source.y == destination.y) && (dirz || source.z == destination.z))
                            {
                                string key = (offsetx + destination.x).ToString() + "." + (offsety + destination.y).ToString() + "." + (offsetz + destination.z).ToString();
                                //get block offset from destination
                                if (filtercrap.ContainsKey(key))
                                {
                                    source.connections.AddRange(filtercrap[key]);
                                }
                                //source.connections.Add(destination.id);
                            }
                        }
                    }
                }
            }

            //apply controllers to bp:

            int amountwired = 0;

            foreach (dynamic body in BP.Blueprint.bodies)
            {
                foreach (dynamic child in body.childs)
                {
                    if (child.controller != null && controllers.ContainsKey(Convert.ToInt32(child.controller.id.ToString())))
                    {
                        int id = Convert.ToInt32(child.controller.id.ToString());
                        if (child.controller.controllers == null)
                        {
                            child.controller.controllers = new JArray();
                        }
                        if (controllers[id].connections != null)
                        {
                            foreach (int destid in controllers[id].connections)
                            {
                                child.controller.controllers.Add(new JObject {
                                    ["id"] = destid
                                });
                                amountwired++;
                            }
                        }
                    }
                }
            }

            new System.Threading.Thread(new System.Threading.ThreadStart(() => {
                MessageBox.Show("Successfully made " + amountwired + " connections! :D");
            })).Start();

            if (amountwired > 0)
            {
                mainwindow.TextBox_Description.Text += "\n--> " + amountwired + " connections made\n";
                BP.Description.description           = BP.Description.description + "\n--> " + amountwired + " connections made\n";
            }

            mainwindow.RenderWires();
            #region somecode

            /*
             * dynamic controllersold = new JObject();
             *
             * dynamic sources = new JObject();
             *
             * foreach (dynamic body in blueprint.bodies)
             *  foreach (dynamic child in body.childs)
             *  {
             *      if (child.controller != null)
             *      {
             *          dynamic rpos = BP.getposandbounds(child);
             *          string x = rpos.pos.x.ToString();
             *          string y = rpos.pos.y.ToString();
             *          string z = rpos.pos.z.ToString();
             *          string color = child.color.ToString();
             *          if (color.StartsWith("#"))
             *              color = color.Substring(1, 6);
             *          //child.shapeId.ToString()
             *          // Convert.ToInt32(child.controller.id.ToString())
             *          dynamic controller = new JObject { [x] = new JObject { [y] = new JObject { [z] = new JObject { [child.color.ToString()] = new JObject { [child.shapeId.ToString()] = new JObject { [color] = Convert.ToInt32(child.controller.id.ToString()) } } } } } };
             *          controllersold.Merge(controller);
             *          if ((sourcecolor == null || sourcecolor == color) && (sourcetype == null || sourcetype == child.shapeId.ToString()))
             *              sources.Merge(controller);
             *      }
             *  }
             *
             *
             * dynamic result = new JObject();//result.DeepClone();
             * //Newtonsoft.Json.Linq.JProperty // keypair
             *
             * if (matchoffset) //ON
             * {//filter only the block with color,type,offset from source
             *  dynamic searchfrom = controllersold.DeepClone();
             *  if (dirx)
             *  {
             *      result = searchfrom;
             *  }
             *  else
             *  {
             *      foreach(JProperty Jprop in sources) //Jprop.Name = "X"
             *      {
             *          string coord = (Convert.ToInt32(Jprop.Name) + offsetx).ToString();
             *          if (searchfrom[coord] != null)
             *          {
             *              result.Merge(new JObject { [coord] = searchfrom[coord] });
             *          }
             *      }
             *  }
             *
             *  searchfrom = result.DeepClone();
             *  result = new JObject();
             *  if (diry)
             *  {
             *      result = searchfrom;
             *  }
             *  else
             *  {
             *      foreach (JProperty JpropSource in sources)
             *      {
             *          string coord = (Convert.ToInt32(JpropSource.Name) + offsetx).ToString();
             *          if (searchfrom[coord] != null)
             *          {
             *              result.Merge(new JObject { [coord] = searchfrom[coord] });
             *          }
             *      }
             *  }
             * }
             * else
             * {//filter all blocks no offset with col&type, then get the ones offset from them (any color, any type)
             *
             * }
             *
             *
             * foreach (dynamic body in blueprint.bodies)
             *  foreach(dynamic child in body.childs)
             *  {
             *      if(child.controller != null && (sourcetype == null || sourcetype == child.shapeId.ToString()))
             *      {
             *          string color = child.color.ToString(); if (color.StartsWith("#")) color = color.Substring(1, 6);
             *          if(sourcecolor == null || color == sourcecolor)
             *          {
             *              dynamic rpos = BP.getposandbounds(child);
             *              int x = Convert.ToInt32(rpos.pos.x.ToString());
             *              int y = Convert.ToInt32(rpos.pos.y.ToString());
             *              int z = Convert.ToInt32(rpos.pos.z.ToString());
             *
             *
             *
             *          }
             *      }
             *  }
             *
             *
             *
             *
             * if (blueprint == "")//false
             * using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.scrapshitConnectionString))
             * {
             *  //conn.ConnectionString = "MyDB";c
             *  int i = 0;
             *  conn.Open();
             *  using (SqlCommand insertCommand = new SqlCommand("DELETE FROM Connections", conn))
             *  {
             *      insertCommand.ExecuteNonQuery();
             *  }
             *  foreach (dynamic body in blueprint.bodies)
             *      foreach (dynamic child in body.childs)
             *      {
             *          if(child.controller != null)
             *          {
             *              dynamic rpos = BP.getposandbounds(child);
             *              string x = rpos.pos.x.ToString();
             *              string y = rpos.pos.y.ToString();
             *              string z = rpos.pos.z.ToString();
             *              string color = child.color.ToString();
             *              if (color.StartsWith("#"))
             *                  color = color.Substring(1, 6);
             *
             *              using (SqlCommand insertCommand = new SqlCommand("INSERT INTO Connections (Controller_Id, posx, posy, posz, color, uuid) VALUES (@controllerid, @x, @y, @z, @color, @uuid)", conn))
             *              {
             *                  insertCommand.Parameters.AddWithValue("@controllerid", Convert.ToInt32(child.controller.id.ToString()));
             *                  insertCommand.Parameters.AddWithValue("@x", x);
             *                  insertCommand.Parameters.AddWithValue("@y", y);
             *                  insertCommand.Parameters.AddWithValue("@z", z);
             *                  insertCommand.Parameters.AddWithValue("@color", color);
             *                  insertCommand.Parameters.AddWithValue("@uuid", child.shapeId.ToString());
             *                  try
             *                  {
             *                      i+= insertCommand.ExecuteNonQuery();
             *                  }
             *                  catch (Exception e)
             *                  {
             *                      MessageBox.Show(e.Message);
             *                  }
             *
             *              }
             *          }
             *      }
             *
             *
             *
             *  //SqlCommand cmd = new SqlCommand("SELECT * FROM Connections WHERE login = @login", conn);
             *
             *  //find all sources  "SELECT * AS 'Sources' FROM Connections" + "WHERE color = @sourcecolor AND uuid = @sourceuuid"
             *  //find all dests?
             *
             *
             *  //string cmd = "SELECT * FROM Description"
             *  //cmd+= "Where uuid = @uuid"
             *  //cmd+= @"AND color = @color"
             *
             *  //all with uuid x / other / all other (match offset block color)
             *  //all with color / all other  / all other (match offset block color)
             *  //all with x + offsetx / other(all in this dir) /x
             *  //all with y + offsety / other / y
             *  //all with z + offsetz /other / z
             *  //exclude self wire?
             *  //if match offset block color search offset from  x y z found blocks (from all, check all current found + offset with color x and type x)
             *
             * }
             *
             *
             *
             * //<x, y, z, color, shapeId>, controllerid
             * Dictionary<Tuple<int, int, int, string, string>, int> dict = new Dictionary<Tuple<int, int, int, string, string>, int>();
             *
             * Dictionary<int, Dictionary<int, Dictionary<int, int>>> testdict = new Dictionary<int, Dictionary<int, Dictionary<int, int>>>();
             * //testdict[5][2][3] = 5;
             *
             */
            #endregion
        }
コード例 #4
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();
        }
コード例 #5
0
        private void filterupdate()
        {
            var l = new Loadwindow();

            l.Show();
            disableAll();
            filter_output.Items.Clear();
            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);

            this.mainwindow.setMarker2((x1 + x2 + 0.0f) / 2, (y1 + y2 + 0.0f) / 2, (z1 + z2 + 0.0f) / 2, (x2 - x1), (y2 - y1), (z2 - z1));
            string targetuuid = null;

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


            //thread:
            if (filter != null && filter.IsAlive)
            {
                filter.Abort();
            }
            filter = new Thread(() =>
            {
                //filter correct blocks:
                int i = 0;
                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))
                        {
                            dynamic listitem   = new JObject();
                            listitem.pos       = new JObject();
                            listitem.pos.x     = (int)realpos.pos.x;
                            listitem.pos.y     = (int)realpos.pos.y;
                            listitem.pos.z     = (int)realpos.pos.z;
                            listitem.bounds    = new JObject();
                            listitem.bounds.x  = (int)realpos.bounds.x;
                            listitem.bounds.y  = (int)realpos.bounds.y;
                            listitem.bounds.z  = (int)realpos.bounds.z;
                            listitem.blockname = "unnamed shape" + child.shapeId.ToString();
                            listitem.index     = i;
                            if (Database.blocks.ContainsKey(child.shapeId.ToString()))
                            {
                                listitem.blockname = Database.blocks[child.shapeId.ToString()].Name;
                            }
                            listitem.color = child.color.ToString();
                            listitem.child = child.ToString();
                            this.Dispatcher.Invoke((Action)(() =>
                            {
                                filter_output.Items.Add(listitem);
                            }));
                        }
                        i++;
                    }
                }
                if (blueprint.joints != null)
                {
                    foreach (dynamic child in blueprint.joints)
                    {
                        if (child.color.ToString().StartsWith("#"))
                        {
                            child.color = child.color.ToString().Substring(1, 6).ToLower();
                        }
                        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))
                        {
                            dynamic listitem   = new JObject();
                            listitem.pos       = new JObject();
                            listitem.pos.x     = (int)realpos.pos.x;
                            listitem.pos.y     = (int)realpos.pos.y;
                            listitem.pos.z     = (int)realpos.pos.z;
                            listitem.bounds    = new JObject();
                            listitem.bounds.x  = (int)realpos.bounds.x;
                            listitem.bounds.y  = (int)realpos.bounds.y;
                            listitem.bounds.z  = (int)realpos.bounds.z;
                            listitem.blockname = "unnamed shape" + child.shapeId.ToString();
                            if (Database.blocks.ContainsKey(child.shapeId.ToString()))
                            {
                                listitem.blockname = Database.blocks[child.shapeId.ToString()].Name;
                            }
                            listitem.color = child.color.ToString();
                            listitem.child = child.ToString();
                            listitem.index = i;
                            this.Dispatcher.Invoke((Action)(() =>
                            {
                                filter_output.Items.Add(listitem);
                            }));
                        }
                        i++;
                    }
                }
            });
            filter.IsBackground = true;
            filter.Start();
            l.Close();
        }
コード例 #6
0
        public void Update()
        {
            if (uuidsbackup != BP.GetUsedUuids())
            {
                usedblocks = new List <Item>
                {
                    new Item("any", "*")
                };
                foreach (string uuid in BP.GetUsedUuids())
                {
                    if (Database.blocks.ContainsKey(uuid))
                    {
                        usedblocks.Add(new Item(Database.blocks[uuid].Name.ToString(), uuid)); // fill the combobox!   only runs once!
                    }
                }
                filter_type.Items.Clear();
                foreach (Item useditem in usedblocks)
                {
                    filter_type.Items.Add(useditem);
                }
            }
            uuidsbackup = BP.GetUsedUuids();
            filter_type.SelectedIndex = 0;
            int i = 0;
            {
                backuplist = new JObject(); //fill 'backup'list with all childs!

                foreach (dynamic body in BP.Blueprint.bodies)
                {
                    foreach (dynamic child in body.childs)
                    {
                        if (child.color.ToString().StartsWith("#"))
                        {
                            child.color = child.color.ToString().Substring(1);
                        }
                        child.blueprintIndex = i;
                        child.blockname      = Database.blocks[child.shapeId.ToString()].Name;
                        dynamic realpos = BP.getposandbounds(child);

                        if (backuplist[realpos.pos.x.ToString()] == null)
                        {
                            backuplist[realpos.pos.x.ToString()] = new JObject();
                        }
                        if (backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()] == null)
                        {
                            backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()] = new JObject();
                        }
                        if (backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()] == null)
                        {
                            backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()] = new JObject();
                        }
                        if (backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()] == null)
                        {
                            backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()] = new JObject();
                        }
                        if (backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()][realpos.shapeId.ToString().ToLower()] == null)
                        {
                            backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()][realpos.shapeId.ToString().ToLower()] = new JObject();
                        }
                        backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()][realpos.shapeId.ToString().ToLower()][i.ToString()] = child;

                        i++;
                    }
                }
            }

            //fill xyz:
            dynamic bounds = BP.GetBounds();

            filter_x1.Text = bounds.minx.ToString();
            filter_y1.Text = bounds.miny.ToString();
            filter_z1.Text = bounds.minz.ToString();
            filter_x2.Text = bounds.maxx.ToString();
            filter_y2.Text = bounds.maxy.ToString();
            filter_z2.Text = bounds.maxz.ToString();

            filterupdate();
        }
コード例 #7
0
        private void filter_output_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            disableAll();
            if (filter_output.SelectedIndex != -1)
            {
                var    bc            = new BrushConverter();
                string selectedcolor = ((dynamic)filter_output.SelectedItem).color;
                string color         = "#FF" + (selectedcolor.StartsWith("#") == true? selectedcolor.Substring(1): selectedcolor);
                //filter_output_color.Fill = (Brush)bc.ConvertFrom(color);
                //clear other options, enable/disable several

                dynamic selectedblock = ((dynamic)filter_output.SelectedItem);

                dynamic realpos = BP.getposandbounds(selectedblock);
                this.mainwindow.setMarker(Convert.ToInt32(realpos.pos.x) + (Convert.ToDouble(realpos.bounds.x) / 2), Convert.ToInt32(realpos.pos.y) + (Convert.ToDouble(realpos.bounds.y) / 2), Convert.ToDouble(realpos.pos.z) + (Convert.ToDouble(realpos.bounds.z) / 2));

                selectedchildindex      = selectedblock.blueprintIndex;
                Edit_general.Visibility = Visibility.Visible;
                new_x.Text     = selectedblock.pos.x;
                new_y.Text     = selectedblock.pos.y;
                new_z.Text     = selectedblock.pos.z;
                new_color.Text = "#" + selectedblock.color;
                new_xaxis.Text = selectedblock.xaxis;
                new_zaxis.Text = selectedblock.zaxis;
                if (selectedblock.controller != null)          //
                {
                    if (selectedblock.controller.mode != null) //logic gate!
                    {
                        new_gatemode.SelectedIndex = selectedblock.controller.mode;
                        Edit_gate.Visibility       = Visibility.Visible;
                        //mode 0-5
                    }
                    if (selectedblock.controller.buttonMode != null)//sensor!
                    {
                        // colorMode & range & color
                        new_sensorcolormode.IsChecked = selectedblock.controller.colorMode;
                        if (selectedblock.controller.colorMode == null)
                        {
                            new_sensorcolormode.IsChecked = false;
                        }
                        new_sensorrange.Text = selectedblock.controller.range;
                        new_sensorcolor.Text = "#" + selectedblock.controller.color;
                        if (selectedblock.controller.color == null)
                        {
                            new_sensorcolor.Text = "#eeeeee";
                        }
                        Edit_sensor.Visibility = Visibility.Visible;
                    }
                    if (selectedblock.controller.luminance != null)//light!
                    {
                        //coneAngle  & luminance
                        new_coneangle.Text   = selectedblock.controller.coneAngle;
                        new_luminance.Text   = selectedblock.controller.luminance;
                        Edit_lamp.Visibility = Visibility.Visible;
                    }
                    if (selectedblock.controller.seconds != null)//timer
                    {
                        //seconds ticks
                        new_timerseconds.Text = selectedblock.controller.seconds;
                        new_timerticks.Text   = selectedblock.controller.ticks;
                        Edit_Timer.Visibility = Visibility.Visible;
                    }

                    if (selectedblock.controller.timePerFrame != null)//controller!
                    {
                        //playMode timePerFrame joints
                        new_controllerloopmode.IsChecked = selectedblock.controller.playMode;
                        new_controllertimeperframe.Text  = selectedblock.controller.timePerFrame;
                        new_controllercontrolls.Items.Clear();
                        if (selectedblock.controller.joints != null)
                        {
                            foreach (dynamic joint in selectedblock.controller.joints)
                            {
                                joint.controller0 = joint.frames[0].targetAngle.ToString();
                                joint.controller1 = joint.frames[1].targetAngle.ToString();
                                joint.controller2 = joint.frames[2].targetAngle.ToString();
                                joint.controller3 = joint.frames[3].targetAngle.ToString();
                                joint.controller4 = joint.frames[4].targetAngle.ToString();
                                joint.controller5 = joint.frames[5].targetAngle.ToString();
                                joint.controller6 = joint.frames[6].targetAngle.ToString();
                                joint.controller7 = joint.frames[7].targetAngle.ToString();
                                joint.controller8 = joint.frames[8].targetAngle.ToString();
                                joint.controller9 = joint.frames[9].targetAngle.ToString();
                                new_controllercontrolls.Items.Add(joint);
                            }
                        }

                        /*
                         * if (selectedblock.controller.controllers != null)
                         *  foreach (dynamic joint in selectedblock.controller.frames)
                         *  {
                         *      joint.controller0 = joint.frames[0].targetAngle.ToString();
                         *      joint.controller1 = joint.frames[1].targetAngle.ToString();
                         *      joint.controller2 = joint.frames[2].targetAngle.ToString();
                         *      joint.controller3 = joint.frames[3].targetAngle.ToString();
                         *      joint.controller4 = joint.frames[4].targetAngle.ToString();
                         *      joint.controller5 = joint.frames[5].targetAngle.ToString();
                         *      joint.controller6 = joint.frames[6].targetAngle.ToString();
                         *      joint.controller7 = joint.frames[7].targetAngle.ToString();
                         *      joint.controller8 = joint.frames[8].targetAngle.ToString();
                         *      joint.controller9 = joint.frames[9].targetAngle.ToString();
                         *      new_controllercontrolls.Items.Add(joint);
                         *
                         *  }*/

                        Edit_controller.Visibility = Visibility.Visible;
                    }
                }
                button_render.IsEnabled = true;
            }
        }