示例#1
0
    public static List <GameObject> ChangeAffectedNumber(int num)
    {
        CompareObjectDistance compDist = new CompareObjectDistance();
        Comparer <GameObject> defComp  = compDist;

        if (num - 1 > affectedParts.Count)
        {
            freeParts.Sort(compDist);

            List <GameObject> transition = new List <GameObject>();
            foreach (GameObject go in freeParts)
            {
                if (num - 1 >= affectedParts.Count)
                {
                    if (TypeFilter.Contains(go.GetComponent <Part>().Name))
                    {
                        AffectPart(go);
                        transition.Add(go);
                    }
                }
                else
                {
                    break;
                }
            }
            foreach (GameObject go in transition)
            {
                freeParts.Remove(go);
            }
        }
        else
        {
            affectedParts.Sort(compDist);

            for (int i = affectedParts.Count - 1; i >= 0; --i)
            {
                if (num < affectedParts.Count)
                {
                    GameObject go = affectedParts[i];
                    go.GetComponent <ConnectionScanning>().enabled = false;
                    go.GetComponent <PartBehaviour>().enabled      = false;
                    go.GetComponent <MeshRenderer>().material      = unaffectedMat;
                    go.GetComponent <ConstantForce>().force        = Vector3.zero;
                    affectedParts.Remove(go);
                    FreeParts.Add(go);
                }
            }
        }

        return(affectedParts);
    }
示例#2
0
        public static void WriteLine(Message message)
        {
            if (!String.IsNullOrEmpty(CallerFilter) && !CallerFilter.Contains(message.Caller.ToString()))
            {
                return;
            }

            if (!String.IsNullOrEmpty(TypeFilter) && !TypeFilter.Contains(message.Type.ToString()))
            {
                return;
            }

            //Dispatcher.CurrentDispatcher.Invoke((Action)(() =>
            //{
            lock (MessageList)
            {
                MessageList.Item.Add(message);
            }
            //}));
            if (MessageReceived != null)
            {
                MessageReceived(new MessagingEventArgs(message));
            }
        }
示例#3
0
        private void LoadDirectory(bool new_location = false)
        {
            if (Walker == null)
            {
                return;
            }

            ResourcesListView.BeginUpdate();
            ResourcesListView.Items.Clear();
            var files = Walker.CurrentContent;

            foreach (var file in files)
            {
                var type = Resource.GetType(file);

                if (type == ResourceType.Folder || TypeFilter == null ||
                    TypeFilter.Length < 1 || TypeFilter.Contains(type))
                {
                    var name = Path.GetFileName(file);
                    int img  = Resource.TypeToIcon(type);
                    if (name == "..")
                    {
                        img = (int)ResourceIcon.PFolder;
                    }
                    var item = ResourcesListView.Items.Add(name, img);

                    if (name == PendRenaming)
                    {
                        item.BeginEdit();
                    }
                }
            }
            ResourcesListView.EndUpdate();
            NameTextBox.Text = Walker.CurrentDirectory.Replace(
                Path.DirectorySeparatorChar, '/');
        }
示例#4
0
        /// <summary>
        /// Returns a node-set
        /// </summary>
        /// <param name="P">
        /// Number of subdivisions in each direction, along one edge.
        /// </param>
        /// <param name="Nodes">
        /// 2D-array, 1st index: node index, 2nd index: spatial direction
        /// </param>
        /// <param name="Type">
        /// The location of the node within the cell; <br/>
        /// Index: node index;
        /// <list type="bullet">
        /// <item>in 1D: 0 for cells (volume nodes, volume is 1D), 1 for vertices (vertex nodes, faces are 0D, i.e. points or vertices)</item>
        /// <item>in 2D: 0 for cells (volume nodes, volume is 2D), <br/>
        ///              1 for edges (face nodes, faces are 1D, i.e. lines),  <br/>
        ///              2 for corners (in 2D the vertices correlate with the co-faces, i.e. 0D objects)</item>
        /// <item>in 3D: 0 for cells (volume nodes, volume is 3D), <br/>
        ///              1 for faces (face nodes, the faces are 2D - polygons, e.g. rectangles or triangles),<br/>
        ///              2 for edges (co-face nodes: co-faces are the edges of the faces; these are lines) <br/>
        ///              3 for corners (etc.) </item>
        /// </list>
        /// </param>
        /// <param name="EntityIndex">
        /// If the k-th node is
        /// <list type="bullet">
        /// <item>a type 0 nodes, i.e. a cell node, <paramref name="EntityIndex"/>[k] is always 0.</item>
        /// <item>a face node, <paramref name="EntityIndex"/>[k] is the index of the face within this reference element.</item>
        /// <item>a co-face node, <paramref name="EntityIndex"/>[k] is the index of the co-face within this reference element</item>
        /// <item>a vertex node, <paramref name="EntityIndex"/>[k] is the index of the vertex within this reference element</item>
        /// </list>
        /// </param>
        /// <param name="TypeFilter">
        /// Node types (see <paramref name="Type"/>) which should be filtered OUT, i.e. nodes with types in <paramref name="TypeFilter"/> will be omitted.
        /// </param>
        public virtual void GetNodeSet(int P, out NodeSet Nodes, out int[] Type, out int[] EntityIndex, params int[] TypeFilter)
        {
            MultidimensionalArray UnsortNodes;

            int[] UnsortType;
            int   D = this.SpatialDimension;

            if (P <= 0)
            {
                throw new ArgumentOutOfRangeException("illegal number of nodes");
            }
            if (P > 1)
            {
                GetNodeSet(P, out UnsortNodes, out UnsortType);
            }
            else
            {
                UnsortNodes = MultidimensionalArray.Create(D + 1, D);
                UnsortNodes.Set(this.Vertices.ExtractSubArrayShallow(new int[] { 0, 0 }, new int[] { D, D - 1 }));
                UnsortType = new int[D + 1];
                UnsortType.SetAll(D);
            }
            if (UnsortNodes.GetLength(0) != UnsortType.Length)
            {
                throw new ApplicationException();
            }
            if (UnsortNodes.GetLength(1) != D)
            {
                throw new ApplicationException();
            }

            if (TypeFilter == null)
            {
                TypeFilter = new int[0];
            }
            else
            {
                foreach (int tf in TypeFilter)
                {
                    if (tf < 0 || tf > D)
                    {
                        throw new ArgumentOutOfRangeException("illegal type filter");
                    }
                }
            }

            Nodes = new NodeSet(this, UnsortNodes.Lengths[0], UnsortNodes.Lengths[1]);
            int NoOfNodes = UnsortType.Length;

            Type        = new int[NoOfNodes];
            EntityIndex = new int[NoOfNodes];

            int      K          = NoOfNodes - 1;
            BitArray Identified = new BitArray(NoOfNodes);

            // identify vertex nodes (1D, 2D and 3D)
            // =====================================
            {
                var V = this.Vertices;

                int Vert_type = D; // 3D: vertex/corner nodes are type 3
                //                 // 2D: vertex/corner nodes are type 2
                //                 // 1D: vertex/corner nodes are type 1
                for (int iVertex = V.GetLength(0) - 1; iVertex >= 0; iVertex--)
                {
                    var v = V.GetRow(iVertex);

                    int    idxFnd = int.MinValue;
                    double dist   = double.MaxValue;
                    for (int i = 0; i < NoOfNodes; i++)
                    {
                        if (Identified[i])
                        {
                            continue;
                        }
                        if (UnsortType[i] != Vert_type)
                        {
                            continue;
                        }
                        var vx = UnsortNodes.GetRow(i);

                        double a = GenericBlas.L2Dist(vx, v);
                        if (a < 1.0e-12)
                        {
                            dist   = a;
                            idxFnd = i;
                        }
                    }

                    if (idxFnd < 0)
                    {
                        if (P > 1)
                        {
                            throw new ApplicationException("Error in implementation.");
                        }
                    }
                    else
                    {
                        Identified[idxFnd] = true;
                        Type[K]            = UnsortType[idxFnd];
                        EntityIndex[K]     = iVertex;
                        Nodes.SetRow(K, v);
                        K--;
                    }
                }
            }

            // identify Co-Face nodes (edges of faces, only 3D)
            // ================================================
            if (D == 3)
            {
                int Vert_type = 2;

                for (int iCoFace = this.NoOfCoFaces - 1; iCoFace >= 0; iCoFace--)   // loop over co-faces
                {
                    var plane0 = this.GetFacePlane(this.CoFace_FaceIndices[iCoFace, 0]);
                    var plane1 = this.GetFacePlane(this.CoFace_FaceIndices[iCoFace, 1]);
                    Debug.Assert(plane0.Normal.Dim == D);
                    Debug.Assert(plane1.Normal.Dim == D);


                    for (int i = 0; i < NoOfNodes; i++)   // loop over all nodes
                    {
                        if (Identified[i])
                        {
                            continue;
                        }
                        if (UnsortType[i] != Vert_type)
                        {
                            continue;
                        }
                        var vx = UnsortNodes.GetRow(i);



                        double a1 = plane0.PointDistance(vx);
                        double a2 = plane1.PointDistance(vx);

                        if (Math.Abs(a1) < 1.0e-10 && Math.Abs(a2) < 1.0e-10)
                        {
                            Identified[i]  = true;
                            Type[K]        = UnsortType[i];
                            EntityIndex[K] = iCoFace;
                            Nodes.SetRow(K, vx);
                            K--;
                        }
                    }
                }
            }

            // identify Face-Nodes (on faces, 2D and 3D)
            // =========================================
            if (D == 2 || D == 3)
            {
                int Vert_type = 1;

                int NoOfFaces = this.NoOfFaces;
                for (int iFace = NoOfFaces - 1; iFace >= 0; iFace--)
                {
                    var    offset = this.FaceCenters.GetRow(iFace);
                    var    normal = this.FaceNormals.GetRow(iFace);
                    double dora   = GenericBlas.InnerProd(offset, normal);

                    for (int i = 0; i < NoOfNodes; i++)
                    {
                        if (Identified[i])
                        {
                            continue;
                        }
                        if (UnsortType[i] != Vert_type)
                        {
                            continue;
                        }
                        var vx = UnsortNodes.GetRow(i);

                        double a = GenericBlas.InnerProd(vx, normal) - dora;
                        if (Math.Abs(a) < 1.0e-10)
                        {
                            Identified[i]  = true;
                            Type[K]        = UnsortType[i];
                            EntityIndex[K] = iFace;
                            Nodes.SetRow(K, vx);
                            K--;
                        }
                    }
                }
            }

            // identify Volume-Nodes (1D, 2D, 3D)
            // ==================================
            {
                int Vert_type = 0;

                for (int i = 0; i < NoOfNodes; i++)
                {
                    if (Identified[i])
                    {
                        if (UnsortType[i] == Vert_type)
                        {
                            throw new ApplicationException("Error in algorithm.");
                        }
                    }
                    else
                    {
                        if (UnsortType[i] != Vert_type)
                        {
                            throw new ApplicationException("Error in algorithm.");
                        }

                        var vx = UnsortNodes.GetRow(i);
                        Identified[i]  = true;
                        Type[K]        = UnsortType[i];
                        EntityIndex[K] = 0;
                        Nodes.SetRow(K, vx);
                        K--;
                    }
                }
            }
            Nodes.LockForever();

            // Apply optional filters
            // ======================
            if (TypeFilter.Length > 0)
            {
                MultidimensionalArray _Nodes = Nodes;
                int[] _Type        = Type;
                int[] _EntityIndex = EntityIndex;


                int NewNoOfNodes = Type.Where(ty => !TypeFilter.Contains(ty)).Count();

                Nodes       = new NodeSet(this, NewNoOfNodes, D);
                Type        = new int[NewNoOfNodes];
                EntityIndex = new int[NewNoOfNodes];

                int kk = 0;
                for (int k = 0; k < NoOfNodes; k++)
                {
                    if (TypeFilter.Contains(_Type[k]))
                    {
                        continue;
                    }

                    Type[kk]        = _Type[k];
                    EntityIndex[kk] = _EntityIndex[kk];
                    Nodes.ExtractSubArrayShallow(kk, -1).Set(_Nodes.ExtractSubArrayShallow(k, -1));

                    kk++;
                }


                Debug.Assert(kk == NewNoOfNodes);

                Nodes.LockForever();
            }
        }