Ejemplo n.º 1
0
        private void Selection(MouseClickType mouseClickType)
        {
            if (_treeModify)
            {
                return;
            }

            _treeModify = true;

            if (mouseClickType == MouseClickType.RightClick)
            {
                // Sets the parent of the current BlockReference as current.
                model1.Entities.SetParentAsCurrent();
            }
            else
            {
                // Deselects the previously selected item
                if (lastSelectedItem != null)
                {
                    lastSelectedItem.Select(model1, false);
                    lastSelectedItem = null;
                }

                var item = model1.GetItemUnderMouseCursor(_mouseLocation);

                if (item != null)
                {
                    lastSelectedItem = item;

                    TreeViewUtility.CleanCurrent(model1, false);

                    // Marks as selected the entity under the mouse cursor.
                    item.Select(model1, true);
                }
                else
                {
                    // Back to the root level
                    if (mouseClickType == MouseClickType.LeftDoubleClick)
                    {
                        TreeViewUtility.CleanCurrent(model1);
                    }
                }
            }

            // An entity in the viewport was selected, so we highlight the corresponding element in the treeview as well
            TreeViewUtility.SynchScreenSelection(treeView1, new Stack <BlockReference>(model1.Entities.Parents), lastSelectedItem);

            model1.Invalidate();

            _treeModify = false;
        }
Ejemplo n.º 2
0
        private void TreeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            if (_treeModify)
            {
                return;
            }

            _treeModify = true;

            //An element of the treeview was selected, so we select the corresponding viewport element as well

            if (lastSelectedItem != null)
            {
                lastSelectedItem.Select(model1, false);
            }

            TreeViewUtility.CleanCurrent(model1);
            lastSelectedItem = TreeViewUtility.SynchTreeSelection(treeView1, model1);

            model1.Invalidate();

            _treeModify = false;
        }
Ejemplo n.º 3
0
        private void BuildAssembly()
        {
            model1.AntiAliasing = (antiAliasingCheckBox.IsChecked == true) ? true : false;
            model1.Rendered.PlanarReflections = (planarCheckBox.IsChecked == true) ? true : false;
            model1.UseShaders = (shadersCheckBox.IsChecked == true) ? true : false;
            model1.WriteDepthForTransparents = (depthCheckBox.IsChecked == true) ? true : false;
            model1.Flat.ShowEdges            = (edgesCheckBox.IsChecked == true) ? true : false;
            model1.HiddenLines.ShowEdges     = (edgesCheckBox.IsChecked == true) ? true : false;
            model1.Rendered.ShowEdges        = (edgesCheckBox.IsChecked == true) ? true : false;
            model1.Shaded.ShowEdges          = (edgesCheckBox.IsChecked == true) ? true : false;
            model1.Wireframe.ShowEdges       = (edgesCheckBox.IsChecked == true) ? true : false;

            _entityList.Clear();
            model1.Entities.Clear();
            model1.Blocks.Clear();

            if (model1.Materials.Count > 0)
            {
                if (!transparencyCheckBox.IsChecked == true)
                {
                    model1.Materials[_wallMatName].Diffuse = System.Drawing.Color.FromArgb(25, 150, 25);
                }
                else
                {
                    model1.Materials[_wallMatName].Diffuse = System.Drawing.Color.FromArgb(100, 25, 150, 25);
                }
            }

            // Variables for unique Mesh (SingleMesh)
            List <Point3D>       globalVerts = new List <Point3D>();
            List <IndexTriangle> globalTris  = new List <IndexTriangle>();
            int offset = globalVerts.Count;

            // Pillar column block
            devDept.Eyeshot.Block column = new devDept.Eyeshot.Block("squareCol");
            // creates a gray box
            Mesh m1 = Mesh.CreateBox(COLUMN_B, COLUMN_H, COLUMN_L);

            // apply texture if Texture is true
            if (textureCheckBox.IsChecked == true)
            {
                m1.ApplyMaterial("Bricks", textureMappingType.Cubic, 1, 1);
            }
            else
            {
                m1.ColorMethod  = colorMethodType.byEntity;
                m1.Color        = System.Drawing.Color.LightGray;
                m1.MaterialName = _concreteMatName;
            }

            for (int i = 0; i < m1.Vertices.Length; i++)
            {
                globalVerts.Add(m1.Vertices[i]);
            }
            for (int i = 0; i < m1.Triangles.Length; i++)
            {
                globalTris.Add(new ColorTriangle(offset + m1.Triangles[i].V1, offset + m1.Triangles[i].V2,
                                                 offset + m1.Triangles[i].V3, System.Drawing.Color.Gray));
            }

            Plane p = new Plane(new Vector3D(0, 1, 0));

            devDept.Eyeshot.Entities.Attribute at = new devDept.Eyeshot.Entities.Attribute(p,
                                                                                           new Point3D(-(TEXT_HEIGHT + TEXT_PAD), COLUMN_B / 2, COLUMN_L / 2), "Name", "Frame", TEXT_HEIGHT);
            at.Alignment  = devDept.Eyeshot.Entities.Text.alignmentType.BaselineCenter;
            at.UpsideDown = true;
            column.Entities.Add(at);

            column.Entities.Add(m1);

            // adds the block to the master block dictionary
            model1.Blocks.Add(column);

            BlockReference reference;

            // Beam
            devDept.Eyeshot.Block beam = new devDept.Eyeshot.Block("beam");
            // creates a gray box
            Mesh m2 = Mesh.CreateBox(BEAM_B, BEAM_L, BEAM_H);

            m2.ColorMethod  = colorMethodType.byEntity;
            m2.Color        = System.Drawing.Color.LightGray;
            m2.MaterialName = _concreteMatName;

            offset = globalVerts.Count;
            for (int i = 0; i < m2.Vertices.Length; i++)
            {
                globalVerts.Add(m2.Vertices[i]);
            }
            for (int i = 0; i < m2.Triangles.Length; i++)
            {
                globalTris.Add(new ColorTriangle(offset + m2.Triangles[i].V1, offset + m2.Triangles[i].V2,
                                                 offset + m2.Triangles[i].V3, System.Drawing.Color.Gray));
            }

            beam.Entities.Add(m2);

            p  = new Plane(new Vector3D(1, 0, 0));
            at = new devDept.Eyeshot.Entities.Attribute(p, new Point3D(BEAM_B / 2, BEAM_L / 2, BEAM_H + TEXT_PAD), "Name",
                                                        "Frame", TEXT_HEIGHT);
            at.Alignment   = devDept.Eyeshot.Entities.Text.alignmentType.BaselineCenter;
            at.Color       = System.Drawing.Color.Green;
            at.ColorMethod = colorMethodType.byEntity;
            beam.Entities.Add(at);

            // adds the block to the master block dictionary
            model1.Blocks.Add(beam);

            // Shell
            devDept.Eyeshot.Block shell = new devDept.Eyeshot.Block("shell");
            double shellB = BEAM_L / _shellSubValue;
            double shellH = COLUMN_L / _shellSubValue;

            // Mesh
            Mesh m3 = Mesh.CreateBox(shellB, SHELL_TICKNESS, shellH);

            m3.ColorMethod  = colorMethodType.byEntity;
            m3.Color        = System.Drawing.Color.LightGreen;
            m3.MaterialName = "wallMat";
            shell.Entities.Add(m3);

            // adds the block to the master block dictionary
            model1.Blocks.Add(shell);

            for (int k = 0; k < _floorsValue; k++)
            {
                for (int j = 0; j <= _bayYValue; j++)
                {
                    for (int i = 0; i <= _bayXValue; i++)
                    {
                        if (pillarsCheckBox.IsChecked == true)
                        {
                            reference = new BlockReference(i * BEAM_L - COLUMN_B / 2, j * BEAM_L - COLUMN_H / 2, k * COLUMN_L,
                                                           "squareCol", 1, 1, 1, 0);
                            if ((structureType)structureModeEnumButton.Value == structureType.SingleMesh)
                            {
                                Mesh mm = (Mesh)model1.Blocks["squareCol"].Entities[1].Clone();
                                mm.Translate(i * BEAM_L - COLUMN_B / 2, j * BEAM_L - COLUMN_H / 2, k * COLUMN_L);
                                offset = globalVerts.Count;
                                globalVerts.AddRange(mm.Vertices);
                                for (int n = 0; n < mm.Triangles.Length; n++)
                                {
                                    globalTris.Add(new ColorTriangle(offset + mm.Triangles[n].V1,
                                                                     offset + mm.Triangles[n].V2, offset + mm.Triangles[n].V3, System.Drawing.Color.Gray));
                                }
                            }

                            if (labelCheckBox.IsChecked == true)
                            {
                                reference.Attributes.Add("Name", string.Format("Pillar_{0},{1},{2}", i, j, k));
                            }
                            _entityList.Add(reference);
                        }

                        if (showBeamXCheckBox.IsChecked == true)
                        {
                            if (j <= _bayYValue && i < _bayXValue)
                            {
                                // Parallel beams to X
                                Transformation t = new Transformation();
                                t.Rotation(-Math.PI / 2, Vector3D.AxisZ);
                                Transformation t2 = new Transformation();
                                t2.Translation(i * BEAM_L, j * BEAM_L + BEAM_B / 2, (k + 1) * COLUMN_L - BEAM_H / 2);
                                reference = new BlockReference(t2 * t, "beam");

                                if ((structureType)structureModeEnumButton.Value == structureType.SingleMesh)
                                {
                                    Mesh mm = (Mesh)model1.Blocks["beam"].Entities[0].Clone();
                                    mm.TransformBy(t2 * t);

                                    offset = globalVerts.Count;
                                    globalVerts.AddRange(mm.Vertices);
                                    for (int n = 0; n < mm.Triangles.Length; n++)
                                    {
                                        globalTris.Add(new ColorTriangle(offset + mm.Triangles[n].V1,
                                                                         offset + mm.Triangles[n].V2, offset + mm.Triangles[n].V3, System.Drawing.Color.Gray));
                                    }
                                }

                                if (labelCheckBox.IsChecked == true)
                                {
                                    reference.Attributes.Add("Name", string.Format("Beam_{0},{1},{2}", i, j, k));
                                }
                                _entityList.Add(reference);
                            }
                        }

                        if (showBeamYCheckBox.IsChecked == true)
                        {
                            if (i <= _bayXValue && j < _bayYValue)
                            {
                                // Parallel beams to X
                                Transformation t = new Transformation();
                                t.Translation(i * BEAM_L - BEAM_B / 2, j * BEAM_L, (k + 1) * COLUMN_L - BEAM_H / 2);
                                reference = new BlockReference(t, "beam");

                                if ((structureType)structureModeEnumButton.Value == structureType.SingleMesh)
                                {
                                    Mesh mm = (Mesh)model1.Blocks["beam"].Entities[0].Clone();
                                    mm.TransformBy(t);
                                    offset = globalVerts.Count;
                                    globalVerts.AddRange(mm.Vertices);
                                    for (int n = 0; n < mm.Triangles.Length; n++)
                                    {
                                        globalTris.Add(new ColorTriangle(offset + mm.Triangles[n].V1,
                                                                         offset + mm.Triangles[n].V2, offset + mm.Triangles[n].V3, System.Drawing.Color.Gray));
                                    }
                                }
                                if (labelCheckBox.IsChecked == true)
                                {
                                    reference.Attributes.Add("Name", string.Format("Beam_{0},{1},{2}", i, j, k));
                                }
                                _entityList.Add(reference);
                            }
                        }

                        if (shellCheckBox.IsChecked == true)
                        {
                            if ((j == 0 || j == _bayYValue) && i < _bayXValue)
                            {
                                for (int i1 = 0; i1 < _shellSubValue; i1++)
                                {
                                    for (int j1 = 0; j1 < _shellSubValue; j1++)
                                    {
                                        Transformation t = new Transformation();
                                        t.Translation(i * BEAM_L + i1 * shellB, j * BEAM_L - SHELL_TICKNESS / 2,
                                                      k * COLUMN_L + j1 * shellH);
                                        reference = new BlockReference(t, "shell");

                                        if ((structureType)structureModeEnumButton.Value == structureType.SingleMesh)
                                        {
                                            Mesh mm = (Mesh)model1.Blocks["shell"].Entities[0].Clone();
                                            mm.TransformBy(t);
                                            offset = globalVerts.Count;
                                            globalVerts.AddRange(mm.Vertices);
                                            for (int n = 0; n < mm.Triangles.Length; n++)
                                            {
                                                globalTris.Add(new ColorTriangle(offset + mm.Triangles[n].V1,
                                                                                 offset + mm.Triangles[n].V2, offset + mm.Triangles[n].V3,
                                                                                 System.Drawing.Color.FromArgb(123, System.Drawing.Color.LightGreen)));
                                            }
                                        }
                                        _entityList.Add(reference);
                                    }
                                }
                            }
                        }
                        if (nodesCheckBox.IsChecked == true)
                        {
                            Joint joint1 = new Joint(i * BEAM_L, j * BEAM_L, k * COLUMN_L, 40, 2);
                            joint1.Color       = System.Drawing.Color.Blue;
                            joint1.ColorMethod = colorMethodType.byEntity;
                            Joint joint2 = new Joint(i * BEAM_L, j * BEAM_L, (k + 1) * COLUMN_L, 40, 2);
                            joint2.Color       = System.Drawing.Color.Blue;
                            joint2.ColorMethod = colorMethodType.byEntity;
                            _entityList.Add(joint1);
                            _entityList.Add(joint2);
                        }
                    }

                    if (shellCheckBox.IsChecked == true)
                    {
                        if (j == 0)
                        {
                            for (int l = 0; l < _bayYValue; l++)
                            {
                                for (int i1 = 0; i1 < _shellSubValue; i1++)
                                {
                                    for (int j1 = 0; j1 < _shellSubValue; j1++)
                                    {
                                        Transformation t = new Transformation();
                                        t.Translation(l * BEAM_L + i1 * shellB, j * BEAM_L - SHELL_TICKNESS / 2,
                                                      k * COLUMN_L + j1 * shellH);
                                        Transformation t2 = new Transformation();
                                        t2.Rotation(Math.PI / 2, Vector3D.AxisZ);
                                        reference = new BlockReference(t2 * t, "shell");

                                        if ((structureType)structureModeEnumButton.Value == structureType.SingleMesh)
                                        {
                                            Mesh mm = (Mesh)model1.Blocks["shell"].Entities[0].Clone();
                                            mm.TransformBy(t2 * t);
                                            offset = globalVerts.Count;
                                            globalVerts.AddRange(mm.Vertices);
                                            for (int n = 0; n < mm.Triangles.Length; n++)
                                            {
                                                globalTris.Add(new ColorTriangle(offset + mm.Triangles[n].V1,
                                                                                 offset + mm.Triangles[n].V2, offset + mm.Triangles[n].V3,
                                                                                 System.Drawing.Color.FromArgb(123, System.Drawing.Color.LightGreen)));
                                            }
                                        }
                                        _entityList.Add(reference);
                                    }
                                }
                            }
                        }
                        if (j == _bayYValue)
                        {
                            for (int l = 0; l < _bayYValue; l++)
                            {
                                for (int i1 = 0; i1 < _shellSubValue; i1++)
                                {
                                    for (int j1 = 0; j1 < _shellSubValue; j1++)
                                    {
                                        Transformation t = new Transformation();
                                        t.Translation(l * BEAM_L + i1 * shellB, -SHELL_TICKNESS / 2, k * COLUMN_L + j1 * shellH);
                                        Transformation t2 = new Transformation();
                                        t2.Rotation(Math.PI / 2, Vector3D.AxisZ);
                                        Transformation t3 = new Transformation();
                                        t3.Translation(_bayXValue * BEAM_L, 0, 0);
                                        reference = new BlockReference(t3 * t2 * t, "shell");

                                        if ((structureType)structureModeEnumButton.Value == structureType.SingleMesh)
                                        {
                                            Mesh mm = (Mesh)model1.Blocks["shell"].Entities[0].Clone();
                                            mm.TransformBy(t3 * t2 * t);
                                            offset = globalVerts.Count;
                                            globalVerts.AddRange(mm.Vertices);
                                            for (int n = 0; n < mm.Triangles.Length; n++)
                                            {
                                                globalTris.Add(new ColorTriangle(offset + mm.Triangles[n].V1,
                                                                                 offset + mm.Triangles[n].V2, offset + mm.Triangles[n].V3,
                                                                                 System.Drawing.Color.FromArgb(123, System.Drawing.Color.LightGreen)));
                                            }
                                        }
                                        _entityList.Add(reference);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            _buildingMesh             = new Mesh(globalVerts, globalTris);
            _buildingMesh.ColorMethod = colorMethodType.byEntity;
            model1.Entities.AddRange(_entityList);

            switch ((structureType)structureModeEnumButton.Value)
            {
            case structureType.Flattened:
            {
                Entity[] entList = model1.Entities.Explode();
                model1.Entities.Clear();
                model1.Entities.AddRange(entList);
                model1.Invalidate();
                break;
            }

            case structureType.SingleMesh:
            {
                model1.Entities.Clear();
                model1.Entities.Add(_buildingMesh);
                model1.Invalidate();
                break;
            }

            case structureType.Assembly:
            {
                model1.Invalidate();
                break;
            }
            }
            TreeViewUtility.PopulateTree(treeView1, model1.Entities.ToList(), model1.Blocks);
        }
Ejemplo n.º 4
0
        private void Model1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Delete)
            {
                TreeNode selectedNode = (TreeNode)treeView1.SelectedItem;
                if (selectedNode != null)
                {
                    if (lastSelectedItem != null && lastSelectedItem.Item != null && lastSelectedItem.Item is BlockReference)
                    {
                        var br = lastSelectedItem.Item as BlockReference;

                        if (selectedNode.ParentNode != null)
                        {
                            var parent = selectedNode.ParentNode.Tag as BlockReference;

                            var parentBlockName = parent.BlockName;

                            foreach (var b in model1.Blocks)
                            {
                                if (b.Name == parentBlockName)
                                {
                                    Entity toDelete = null;

                                    foreach (var ent in b.Entities)
                                    {
                                        if (ent == br)
                                        {
                                            toDelete = ent;
                                        }
                                    }

                                    if (toDelete != null)
                                    {
                                        b.Entities.Remove(toDelete);
                                    }
                                }
                            }
                        }
                        else // Root entity is to delete
                        {
                            treeView1.Items.Remove(selectedNode);

                            model1.Entities.Remove(br);
                            model1.Invalidate();
                        }
                    }
                    else if (lastSelectedItem.Item is Entity)
                    {
                        var entity = lastSelectedItem.Item as Entity;

                        foreach (var b in model1.Blocks)
                        {
                            if (b.Entities.Contains(entity))
                            {
                                b.Entities.Remove(entity);
                            }
                        }

                        model1.Entities.DeleteSelected(); // in case the entity to delete is the root entity
                    }

                    TreeViewUtility.DeleteSelectedNode(treeView1, model1);
                    treeView1.Items.Remove(selectedNode);
                }
            }
        }