Ejemplo n.º 1
0
        private void lstIndexes_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.lstIndexes.SelectedItems.Count != 1)
            {
                return;
            }
            IIndexMap   pIndexMap   = ((IIndexMap)lstIndexes.SelectedItems[0].Tag);
            string      oldName     = pIndexMap.Name;
            frmIndexMap indexMapFrm = new frmIndexMap(txtDB.Text, pIndexMap, _plugin);

            if (indexMapFrm.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            lstIndexes.Items.Remove(this.lstIndexes.SelectedItems[0]);
            _plugin.PrintingConfig.IndexMaps.Remove(pIndexMap);
            IIndexMap indexMap = indexMapFrm.IndexMap;
            IIndexMap oldIdx   = _plugin.PrintingConfig.IndexMaps.FirstOrDefault(c => c.Name == indexMap.Name);

            if (oldIdx != null)
            {
                MessageService.Current.Warn("同名索引设置以及存在,无法保存!");
                return;
            }
            _plugin.PrintingConfig.IndexMaps.Add(indexMap);
            ListViewItem item = new ListViewItem(new string[]
            {
                indexMap.Name, indexMap.IndexLayerName, indexMap.TemplateName, indexMap.SearchFields,
                indexMap.NameField
            });

            item.Tag = indexMap;
            lstIndexes.Items.Add(item);
        }
Ejemplo n.º 2
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            frmIndexMap indexMapFrm = new frmIndexMap(txtDB.Text, new IndexMap(), _plugin);

            if (indexMapFrm.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            IIndexMap indexMap = indexMapFrm.IndexMap;
            IIndexMap oldIdx   = _plugin.PrintingConfig.IndexMaps.FirstOrDefault(c => c.Name == indexMap.Name);

            if (oldIdx != null)
            {
                MessageService.Current.Warn("同名索引设置以及存在,无法保存!");
                return;
            }
            _plugin.PrintingConfig.IndexMaps.Add(indexMap);
            ListViewItem item = new ListViewItem(new string[]
            {
                indexMap.Name, indexMap.IndexLayerName, indexMap.TemplateName, indexMap.SearchFields,
                indexMap.NameField
            });

            item.Tag = indexMap;
            lstIndexes.Items.Add(item);
        }
Ejemplo n.º 3
0
        public DenseUVMesh            UVs;              // separate UV layer (just one for now)
        // assumption is that # of triangles in this UV mesh is same as in Mesh

        public WriteMesh(IMesh mesh, string name = "")
        {
            Mesh             = mesh;
            Name             = name;
            UVs              = null;
            Materials        = null;
            TriToMaterialMap = null;
        }
Ejemplo n.º 4
0
        public static void Apply(int[] indices, IIndexMap map)
        {
            int N = indices.Length;

            for (int i = 0; i < N; ++i)
            {
                indices[i] = map[indices[i]];
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Apply map to indices
        /// </summary>
        public static void Apply(List <int> indices, IIndexMap map)
        {
            int N = indices.Count;

            for (int i = 0; i < N; ++i)
            {
                indices[i] = map[indices[i]];
            }
        }
Ejemplo n.º 6
0
 public frmIndexMap(string connectionString, IIndexMap indexMap, PrintingPlugin plugin)
 {
     InitializeComponent();
     _connectionString = connectionString;
     _indexMap         = indexMap;
     _plugin           = plugin;
     FillTemplate();
     FillIndexMap();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// given list of edges of MeshA, and vertex map from A to B, map to list of edges on B
        /// </summary>
        public static List <int> MapEdgesViaVertexMap(IIndexMap AtoBV, DMesh3 MeshA, DMesh3 MeshB, List <int> edges)
        {
            int        N      = edges.Count;
            List <int> result = new List <int>(N);

            for (int i = 0; i < N; ++i)
            {
                int     eid_a = edges[i];
                Index2i aev   = MeshA.GetEdgeV(eid_a);
                int     bev0  = AtoBV[aev.a];
                int     bev1  = AtoBV[aev.b];
                int     eid_b = MeshB.FindEdge(bev0, bev1);
                Debug.Assert(eid_b != DMesh3.InvalidID);
                result.Add(eid_b);
            }
            return(result);
        }
Ejemplo n.º 8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            IIndexMap indexMap = new IndexMap()
            {
                Name           = txtName.Text,
                TemplateName   = cmbTemplate.EditValue.ToString(),
                IndexLayerName = txtLayer.EditValue.ToString(),
                WorkspaceName  = txtLayer.Tag.ToString(),
                NameField      = cmbNameField.EditValue.ToString()
            };

            string cc = "";

            foreach (var item in chkQueryFields.SelectedItems)
            {
                cc += ";" + item.ToString();
            }
            cc = cc.Substring(1);
            indexMap.SearchFields = cc;
            _indexMap             = indexMap;
            DialogResult          = DialogResult.OK;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// given EdgeLoop on MeshA, and vertex map from A to B, map to EdgeLoop on B
        /// </summary>
        public static EdgeLoop MapLoopViaVertexMap(IIndexMap AtoBV, DMesh3 MeshA, DMesh3 MeshB, EdgeLoop loopIn)
        {
            int NV = loopIn.VertexCount, NE = loopIn.EdgeCount;

            int[] newVerts = new int[NV];
            for (int i = 0; i < NV; ++i)
            {
                newVerts[i] = AtoBV[loopIn.Vertices[i]];
            }

            int[] newEdges = new int[NE];
            for (int i = 0; i < NE; ++i)
            {
                int     eid_a = loopIn.Edges[i];
                Index2i aev   = MeshA.GetEdgeV(eid_a);
                int     bev0  = AtoBV[aev.a];
                int     bev1  = AtoBV[aev.b];
                newEdges[i] = MeshB.FindEdge(bev0, bev1);
                Debug.Assert(newEdges[i] != DMesh3.InvalidID);
            }

            return(new EdgeLoop(MeshB, newVerts, newEdges, false));
        }
Ejemplo n.º 10
0
        private void btnKeySearch_Click(object sender, EventArgs e)
        {
            if (cmbIndexMap.SelectedIndex < 0)
            {
                MessageService.Current.Warn("请选择索引图!");
                return;
            }
            if (string.IsNullOrEmpty(txtSearchKey.EditValue.ToString()))
            {
                MessageService.Current.Warn("请输入搜素关键字!");
                return;
            }
            IIndexMap      indexMap = _indexMaps[cmbIndexMap.SelectedIndex];
            IFeatureCursor pCursor  = indexMap.Search(txtSearchKey.Text);

            if (pCursor == null)
            {
                return;
            }
            IFeature pFeature = pCursor.NextFeature();
            int      nameIdx  = pCursor.FindField(indexMap.NameField);

            lstIndexFeatures.Items.Clear();
            while (pFeature != null)
            {
                string pName = nameIdx >= 0 ? pFeature.Value[nameIdx].ToString() : "";
                if (!pFeature.Shape.IsEmpty)
                {
                    IndexFeatureItem item = new IndexFeatureItem(pFeature.OID, pFeature.Shape.Envelope, pName);
                    lstIndexFeatures.Items.Add(item);
                }

                pFeature = pCursor.NextFeature();
            }
            ComReleaser.ReleaseCOMObject(pCursor);
        }
Ejemplo n.º 11
0
        public IOWriteResult Write(TextWriter writer, List <WriteMesh> vMeshes, WriteOptions options)
        {
            if (options.groupNamePrefix != null)
            {
                GroupNamePrefix = options.groupNamePrefix;
            }
            if (options.GroupNameF != null)
            {
                GroupNameF = options.GroupNameF;
            }

            int nAccumCountV  = 1;      // OBJ indices always start at 1
            int nAccumCountUV = 1;

            // collect materials
            string sMaterialLib   = "";
            int    nHaveMaterials = 0;

            if (options.bWriteMaterials && options.MaterialFilePath.Length > 0)
            {
                List <GenericMaterial> vMaterials = MeshIOUtil.FindUniqueMaterialList(vMeshes);
                IOWriteResult          ok         = write_materials(vMaterials, options);
                if (ok.code == IOCode.Ok)
                {
                    sMaterialLib   = Path.GetFileName(options.MaterialFilePath);
                    nHaveMaterials = vMeshes.Count;
                }
            }


            if (options.AsciiHeaderFunc != null)
            {
                writer.WriteLine(options.AsciiHeaderFunc());
            }

            if (sMaterialLib != "")
            {
                writer.WriteLine("mtllib {0}", sMaterialLib);
            }

            for (int mi = 0; mi < vMeshes.Count; ++mi)
            {
                IMesh mesh = vMeshes[mi].Mesh;

                if (options.ProgressFunc != null)
                {
                    options.ProgressFunc(mi, vMeshes.Count - 1);
                }

                bool bVtxColors = options.bPerVertexColors && mesh.HasVertexColors;
                bool bNormals   = options.bPerVertexNormals && mesh.HasVertexNormals;

                // use separate UV set if we have it, otherwise write per-vertex UVs if we have those
                bool bVtxUVs = options.bPerVertexUVs && mesh.HasVertexUVs;
                if (vMeshes[mi].UVs != null)
                {
                    bVtxUVs = false;
                }

                int[] mapV = new int[mesh.MaxVertexID];

                // write vertices for this mesh
                foreach (int vi in mesh.VertexIndices())
                {
                    mapV[vi] = nAccumCountV++;
                    Vector3d v = mesh.GetVertex(vi);
                    if (bVtxColors)
                    {
                        Vector3d c = mesh.GetVertexColor(vi);
                        writer.WriteLine("v {0} {1} {2} {3:F8} {4:F8} {5:F8}", v[0], v[1], v[2], c[0], c[1], c[2]);
                    }
                    else
                    {
                        writer.WriteLine("v {0} {1} {2}", v[0], v[1], v[2]);
                    }

                    if (bNormals)
                    {
                        Vector3d n = mesh.GetVertexNormal(vi);
                        writer.WriteLine("vn {0:F10} {1:F10} {2:F10}", n[0], n[1], n[2]);
                    }

                    if (bVtxUVs)
                    {
                        Vector2f uv = mesh.GetVertexUV(vi);
                        writer.WriteLine("vt {0:F10} {1:F10}", uv.x, uv.y);
                    }
                }

                // write independent UVs for this mesh, if we have them
                IIndexMap   mapUV = (bVtxUVs) ? new IdentityIndexMap() : null;
                DenseUVMesh uvSet = null;
                if (vMeshes[mi].UVs != null)
                {
                    uvSet = vMeshes[mi].UVs;
                    int      nUV     = uvSet.UVs.Length;
                    IndexMap fullMap = new IndexMap(false, nUV);                       // [TODO] do we really need a map here? is just integer shift, no?
                    for (int ui = 0; ui < nUV; ++ui)
                    {
                        writer.WriteLine("vt {0:F8} {1:F8}", uvSet.UVs[ui].x, uvSet.UVs[ui].y);
                        fullMap[ui] = nAccumCountUV++;
                    }
                    mapUV = fullMap;
                }

                // check if we need to write usemtl lines for this mesh
                bool bWriteMaterials = nHaveMaterials > 0 &&
                                       vMeshes[mi].TriToMaterialMap != null &&
                                       vMeshes[mi].Materials != null;

                // various ways we can write triangles to minimize state changes...
                // [TODO] support writing materials when mesh has groups!!
                if (options.bWriteGroups && mesh.HasTriangleGroups)
                {
                    write_triangles_bygroup(writer, mesh, mapV, uvSet, mapUV, bNormals);
                }
                else
                {
                    write_triangles_flat(writer, vMeshes[mi], mapV, uvSet, mapUV, bNormals, bWriteMaterials);
                }
            }


            return(new IOWriteResult(IOCode.Ok, ""));
        }
Ejemplo n.º 12
0
        // sequential write of input mesh triangles. preserves triangle IDs up to constant shift.
        void write_triangles_flat(TextWriter writer, WriteMesh write_mesh, int[] mapV, DenseUVMesh uvSet, IIndexMap mapUV, bool bNormals, bool bMaterials)
        {
            bool bUVs = (mapUV != null);

            int cur_material = -1;

            IMesh mesh = write_mesh.Mesh;

            foreach (int ti in mesh.TriangleIndices())
            {
                if (bMaterials)
                {
                    set_current_material(writer, ti, write_mesh, ref cur_material);
                }

                Index3i t = mesh.GetTriangle(ti);
                t[0] = mapV[t[0]];
                t[1] = mapV[t[1]];
                t[2] = mapV[t[2]];

                if (bUVs)
                {
                    Index3i tuv = (uvSet != null) ? uvSet.TriangleUVs[ti] : t;
                    tuv[0] = mapUV[tuv[0]];
                    tuv[1] = mapUV[tuv[1]];
                    tuv[2] = mapUV[tuv[2]];
                    write_tri(writer, ref t, bNormals, true, ref tuv);
                }
                else
                {
                    write_tri(writer, ref t, bNormals, false, ref t);
                }
            }
        }
Ejemplo n.º 13
0
        // write triangles of mesh with re-ordering to minimize group changes
        // (note: this may mean lots of material changes, depending on mesh...)
        void write_triangles_bygroup(TextWriter writer, IMesh mesh, int[] mapV, DenseUVMesh uvSet, IIndexMap mapUV, bool bNormals)
        {
            // This makes N passes over mesh indices, but doesn't use much extra memory.
            // would there be a faster way? could construct integer-pointer-list during initial
            // scan, this would need O(N) memory but then write is effectively O(N) instead of O(N*k)

            bool bUVs = (mapUV != null);

            HashSet <int> vGroups = new HashSet <int>();

            foreach (int ti in mesh.TriangleIndices())
            {
                vGroups.Add(mesh.GetTriangleGroup(ti));
            }

            List <int> sortedGroups = new List <int>(vGroups);

            sortedGroups.Sort();
            foreach (int g in sortedGroups)
            {
                string group_name = GroupNamePrefix;
                if (GroupNameF != null)
                {
                    group_name = GroupNameF(g);
                }
                else
                {
                    group_name = string.Format("{0}{1}", GroupNamePrefix, g);
                }
                writer.WriteLine("g " + group_name);

                foreach (int ti in mesh.TriangleIndices())
                {
                    if (mesh.GetTriangleGroup(ti) != g)
                    {
                        continue;
                    }

                    Index3i t = mesh.GetTriangle(ti);
                    t[0] = mapV[t[0]];
                    t[1] = mapV[t[1]];
                    t[2] = mapV[t[2]];

                    if (bUVs)
                    {
                        Index3i tuv = (uvSet != null) ? uvSet.TriangleUVs[ti] : t;
                        tuv[0] = mapUV[tuv[0]];
                        tuv[1] = mapUV[tuv[1]];
                        tuv[2] = mapUV[tuv[2]];
                        write_tri(writer, ref t, bNormals, true, ref tuv);
                    }
                    else
                    {
                        write_tri(writer, ref t, bNormals, false, ref t);
                    }
                }
            }
        }
Ejemplo n.º 14
0
 public IndexMapInfo(IIndexMap indexMap)
 {
     _indexMap = indexMap;
 }
Ejemplo n.º 15
0
        private void DeleteIndexEntries(IIndexMap map, string id)
        {
            var query = string.Format("delete from {0} where DocumentId=?", map.ResultType.Name);

            _store.Connection.Execute(query, id);
        }