示例#1
0
 public void Update()//new bp, items replaced, ... whatever
 {
     disableAll();
     if (filter_x1.Text == "" || uuidsbackup != BP.GetUsedUuids())
     {
         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();
     }
     if (uuidsbackup != BP.GetUsedUuids() | true)//fill the combobox once
     {
         filter_type.Items.Clear();
         filter_type.Items.Add(new Item("any", "*"));
         foreach (string uuid in BP.GetUsedUuids())
         {
             if (Database.blocks.ContainsKey(uuid))
             {
                 filter_type.Items.Add(new Item(Database.blocks[uuid].Name.ToString(), uuid));
             }
         }
         uuidsbackup.Clear();
         uuidsbackup.UnionWith(BP.GetUsedUuids());
         filter_type.SelectedIndex = 0;
     }
     filterupdate();
 }
        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();
        }
        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();
        }
        //Thread filter;

        private void filter_output_update()
        {
            {
                dynamic bounds = BP.GetBounds();
                int     x1 = bounds.minx, y1 = bounds.maxx, z1 = bounds.miny, x2 = bounds.maxy, y2 = bounds.minz, z2 = bounds.maxz;
                string  type = "*";//nullable! = any

                this.Dispatcher.Invoke((Action)(() =>
                {//this refer to form in WPF application
                    if (filter_output.Items.Count > 0)
                    {
                        filter_output.Items.Clear();
                    }
                    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
                    }
                    if (filter_type.SelectedIndex < 0)
                    {
                        filter_type.SelectedIndex = 0;
                    }
                    if (filter_type.SelectedIndex >= 0)
                    {
                        type = ((Item)filter_type.SelectedItem).UUID;
                    }
                    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 color = filtercolor;//nullable! = any


                for (int x = x1; x <= x2; x++)
                {
                    if (backuplist[x.ToString()] != null)
                    {
                        for (int y = y1; y < y2; y++)
                        {
                            if (backuplist[x.ToString()][y.ToString()] != null)
                            {
                                for (int z = z1; z < z2; z++)
                                {
                                    if (backuplist[x.ToString()][y.ToString()][z.ToString()] != null)
                                    {
                                        if (color == null)
                                        {
                                            foreach (dynamic xyzcolor in backuplist[x.ToString()][y.ToString()][z.ToString()])
                                            {
                                                if (type == "*")
                                                {
                                                    foreach (dynamic childuuid in xyzcolor.Value)
                                                    {
                                                        foreach (dynamic child in childuuid.Value)
                                                        {
                                                            this.Dispatcher.Invoke((Action)(() =>
                                                            {                                         //this refer to form in WPF application
                                                                filter_output.Items.Add(child.Value); //any color any type
                                                            }));
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (xyzcolor.Value[type.ToLower()] != null)
                                                    {
                                                        foreach (dynamic child in xyzcolor.Value[type.ToLower()])
                                                        {
                                                            this.Dispatcher.Invoke((Action)(() =>
                                                            {                                         //this refer to form in WPF application
                                                                filter_output.Items.Add(child.Value); //any color , one type
                                                            }));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (color.StartsWith("#"))
                                            {
                                                color = color.Substring(1).ToLower();
                                            }
                                            if (backuplist[x.ToString()][y.ToString()][z.ToString()][color] != null)
                                            {
                                                if (type == "*")
                                                {
                                                    foreach (dynamic childuuid in backuplist[x.ToString()][y.ToString()][z.ToString()][color])
                                                    {
                                                        foreach (dynamic child in childuuid.Value)
                                                        {
                                                            this.Dispatcher.Invoke((Action)(() =>
                                                            {                                         //this refer to form in WPF application
                                                                filter_output.Items.Add(child.Value); //one color , any type
                                                            }));
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (backuplist[x.ToString()][y.ToString()][z.ToString()][color][type] != null)
                                                    {
                                                        foreach (dynamic child in backuplist[x.ToString()][y.ToString()][z.ToString()][color][type])
                                                        {
                                                            this.Dispatcher.Invoke((Action)(() =>
                                                            {                                         //this refer to form in WPF application
                                                                filter_output.Items.Add(child.Value); //one color, one type
                                                            }));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                try
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {//this refer to form in WPF application
                        disableAll();
                    }));
                }
                catch { }
            }
        }