private IPolilinea ReadPolilinea(ref ParCodigoValor cod) { string handle = string.Empty; //Layer layer = Layer.Default; //AciColor color = AciColor.ByLayer; //LineType lineType = LineType.ByLayer; PolylineTypeFlags flags = PolylineTypeFlags.OpenPolyline; float elevation = 0.0f; float thickness = 0.0f; Vector3f normal = Vector3f.UnitarioZ; List<Vertex> vertexes = new List<Vertex>(); //Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>(); //int numVertexes = -1; //int numFaces = -1; cod = this.ReadCodePair(); while (cod.Cod != 0) { switch (cod.Cod) { case 5: handle = cod.Val; cod = this.ReadCodePair(); break; //case 8: // layer = this.GetLayer(cod.Value); // cod = this.ReadCodePair(); // break; //case 62: // color = new AciColor(short.Parse(code.Value)); // code = this.ReadCodePair(); // break; //case 6: // lineType = this.GetLineType(code.Value); // code = this.ReadCodePair(); // break; case 30: elevation = float.Parse(cod.Val); cod = this.ReadCodePair(); break; case 39: thickness = float.Parse(cod.Val); cod = this.ReadCodePair(); break; case 70: flags = (PolylineTypeFlags)(int.Parse(cod.Val)); cod = this.ReadCodePair(); break; case 71: //this field might not exist for polyface meshes, we cannot depend on it //numVertexes = int.Parse(code.Value); code = this.ReadCodePair(); cod = this.ReadCodePair(); break; case 72: //this field might not exist for polyface meshes, we cannot depend on it //numFaces = int.Parse(code.Value); cod = this.ReadCodePair(); break; case 210: normal.X = float.Parse(cod.Val); cod = this.ReadCodePair(); break; case 220: normal.Y = float.Parse(cod.Val); cod = this.ReadCodePair(); break; case 230: normal.Z = float.Parse(cod.Val); cod = this.ReadCodePair(); break; //case 1001: // XData xDataItem = this.ReadXDataRecord(code.Value, ref code); // xData.Add(xDataItem.ApplicationRegistry, xDataItem); // break; default: if (cod.Cod >= 1000 && cod.Cod <= 1071) throw new DxfInvalidCodeValueEntityException(cod.Cod, cod.Val, this.archivo, "The extended data of an entity must start with the application registry code " + this.fileLine); cod = this.ReadCodePair(); break; } } //begin to read the vertex list if (cod.Val != DxfCodigoObjeto.Vertex) throw new DxfEntityException(DxfCodigoObjeto.Polilinea, this.archivo, "Vertex not found in line " + this.fileLine); while (cod.Val != StringCode.EndSequence) { if (cod.Val == DxfCodigoObjeto.Vertex) { Debug.Assert(cod.Cod == 0); Vertex vertex = this.ReadVertex(ref cod); vertexes.Add(vertex); } } // read the end end sequence object until a new element is found if (cod.Val != StringCode.EndSequence) throw new DxfEntityException(DxfCodigoObjeto.Polilinea, this.archivo, "End sequence entity not found in line " + this.fileLine); cod = this.ReadCodePair(); string endSequenceHandle = string.Empty; //Layer endSequenceLayer = layer; while (cod.Cod != 0) { switch (cod.Cod) { case 5: endSequenceHandle = cod.Val; cod = this.ReadCodePair(); break; //case 8: // endSequenceLayer = this.GetLayer(code.Value); // code = this.ReadCodePair(); // break; default: cod = this.ReadCodePair(); break; } } IPolilinea pol; bool isClosed = false; if ((flags & PolylineTypeFlags.ClosedPolylineOrClosedPolygonMeshInM) == PolylineTypeFlags.ClosedPolylineOrClosedPolygonMeshInM) { isClosed = true; } //to avoid possible error between the vertex type and the polyline type //the polyline type will decide which information to use from the read vertex if ((flags & PolylineTypeFlags.Polyline3D) == PolylineTypeFlags.Polyline3D) { List<Polyline3dVertex> polyline3dVertexes = new List<Polyline3dVertex>(); foreach (Vertex v in vertexes) { Polyline3dVertex vertex = new Polyline3dVertex { //Color = v.Color, //Layer = v.Layer, //LineType = v.LineType, Location = v.Location, Handle = v.Handle }; //vertex.XData = v.XData; polyline3dVertexes.Add(vertex); } ////posible error avoidance, the polyline is marked as polyline3d code:(70,8) but the vertex is marked as PolylineVertex code:(70,0) //if (v.Type == EntityType.PolylineVertex) //{ // Polyline3dVertex polyline3dVertex = new Polyline3dVertex(((PolylineVertex)v).Location.X, ((PolylineVertex)v).Location.Y,0); // polyline3dVertexes.Add(polyline3dVertex); //} //else //{ // polyline3dVertexes.Add((Polyline3dVertex)v); //} //} pol = new Polyline3d(polyline3dVertexes, isClosed) { Handle = handle }; //((Polyline3d)pol).EndSequence.Handle = endSequenceHandle; //((Polyline3d)pol).EndSequence.Layer = endSequenceLayer; } else if ((flags & PolylineTypeFlags.PolyfaceMesh) == PolylineTypeFlags.PolyfaceMesh) { //the vertex list created contains vertex and face information List<PolyfaceMeshVertex> polyfaceVertexes = new List<PolyfaceMeshVertex>(); List<PolyfaceMeshFace> polyfaceFaces = new List<PolyfaceMeshFace>(); foreach (Vertex v in vertexes) { if ((v.Flags & (VertexTypeFlags.PolyfaceMeshVertex | VertexTypeFlags.Polygon3dMesh)) == (VertexTypeFlags.PolyfaceMeshVertex | VertexTypeFlags.Polygon3dMesh)) { PolyfaceMeshVertex vertex = new PolyfaceMeshVertex { //Color = v.Color, //Layer = v.Layer, //LineType = v.LineType, Location = v.Location, Handle = v.Handle }; //vertex.XData = xData; polyfaceVertexes.Add(vertex); } else if ((v.Flags & (VertexTypeFlags.PolyfaceMeshVertex)) == (VertexTypeFlags.PolyfaceMeshVertex)) { PolyfaceMeshFace vertex = new PolyfaceMeshFace { //Color = v.Color, //Layer = v.Layer, //LineType = v.LineType, VertexIndexes = v.VertexIndexes, Handle = v.Handle }; //vertex.XData = xData; polyfaceFaces.Add(vertex); } //if (v.Type == EntityType.PolyfaceMeshVertex) //{ // polyfaceVertexes.Add((PolyfaceMeshVertex) v); //} //else if (v.Type == EntityType.PolyfaceMeshFace) //{ // polyfaceFaces.Add((PolyfaceMeshFace) v); //} //else //{ // throw new EntityDxfException(v.Type.ToString(), this.file, "Error in vertex type."); //} } pol = new PolyfaceMesh(polyfaceVertexes, polyfaceFaces) { Handle = handle }; //((PolyfaceMesh)pol).EndSequence.Handle = endSequenceHandle; //((PolyfaceMesh)pol).EndSequence.Layer = endSequenceLayer; } else { List<PolylineVertex> polylineVertexes = new List<PolylineVertex>(); foreach (Vertex v in vertexes) { PolylineVertex vertex = new PolylineVertex { Location = new Vector2f(v.Location.X, v.Location.Y), BeginThickness = v.BeginThickness, Bulge = v.Bulge, //Color = v.Color, EndThickness = v.EndThickness, //Layer = v.Layer, //LineType = v.LineType, Handle = v.Handle }; //vertex.XData = xData; ////posible error avoidance, the polyline is marked as polyline code:(70,0) but the vertex is marked as Polyline3dVertex code:(70,32) //if (v.Type==EntityType.Polyline3dVertex) //{ // PolylineVertex polylineVertex = new PolylineVertex(((Polyline3dVertex)v).Location.X, ((Polyline3dVertex)v).Location.Y); // polylineVertexes.Add(polylineVertex); //} //else //{ // polylineVertexes.Add((PolylineVertex) v); //} polylineVertexes.Add(vertex); } pol = new Polilinea(polylineVertexes, isClosed) { //Thickness = thickness, Elevation = elevation, Normal = normal, Handle = handle }; //((Polilinea)pol).EndSequence.Handle = endSequenceHandle; //((Polilinea)pol).EndSequence.Layer = endSequenceLayer; } //pol.Color = color; //pol.Layer = layer; //pol.LineType = lineType; //pol.XData = xData; return pol; }
public static List<string> Polilinea(IPolilinea p) { G01_Lineal mov; List<string> movs = new List<string>(); Polilinea pi = new Polilinea(); if (p.Tipo == EntidadTipo.Polilinea) { pi = (Polilinea)p; } if (p.Tipo == EntidadTipo.LightWeightPolyline) { pi = ((LightWeightPolyline)p).ToPolilinea(); } foreach (PolylineVertex v in pi.Vertexes) { mov = new G01_Lineal(); mov.Inicio.X = v.Location.X; mov.Inicio.Y = v.Location.Y; mov.Inicio.Z = pi.Elevation; mov.Fin.X = v.Location.X; mov.Fin.Y = v.Location.Y; mov.Fin.Z = pi.Elevation; movs.Add(mov.ToString()); } if (pi.IsClosed) //si es cerrado, adicionalmente agregamos ir al inicio { mov = new G01_Lineal(); mov.Inicio.X = pi.Vertexes[pi.Vertexes.Count - 1].Location.X; mov.Inicio.Y = pi.Vertexes[pi.Vertexes.Count - 1].Location.Y; mov.Inicio.Z = pi.Elevation; mov.Fin.X = pi.Vertexes[0].Location.X; mov.Fin.Y = pi.Vertexes[0].Location.Y; mov.Fin.Z = pi.Elevation; movs.Add(mov.ToString()); } return movs; }
public static List<string> Polilineas(ReadOnlyCollection<IPolilinea> polilineas) { G01_Lineal mov; List<string> movs = new List<string>(); foreach (IPolilinea p in polilineas) { //movs.Add("<polilinea>"); Polilinea pi = new Polilinea(); if (p.Tipo == EntidadTipo.Polilinea) { pi = (Polilinea)p; } if (p.Tipo == EntidadTipo.LightWeightPolyline) { pi = ((LightWeightPolyline)p).ToPolilinea(); } int i = 0; foreach (PolylineVertex v in pi.Vertexes) { mov = new G01_Lineal(); mov.Inicio.X = v.Location.X; mov.Inicio.Y = v.Location.Y; mov.Inicio.Z = pi.Elevation; mov.Fin.X = v.Location.X; mov.Fin.Y = v.Location.Y; mov.Fin.Z = pi.Elevation; if (i == 0) { movs.Add(Metodos.IrA(mov.Inicio.X, mov.Inicio.Y, mov.Inicio.Z)); } else if (i == 1) { //movs.Add(Metodos.IrA(pi.Vertexes[i - 1].Location.X, pi.Vertexes[i - 1].Location.Y, 0)); movs.Add(mov.ToString()); } else { movs.Add(Metodos.IrA(pi.Vertexes[i - 1].Location.X, pi.Vertexes[i - 1].Location.Y, pi.Elevation)); movs.Add(mov.ToString()); } i++; } if (pi.IsClosed) //si es cerrado, adicionalmente agregamos ir al inicio { mov = new G01_Lineal(); mov.Inicio.X = pi.Vertexes[0].Location.X; mov.Inicio.Y = pi.Vertexes[0].Location.Y; mov.Inicio.Z = pi.Elevation; mov.Fin.X = pi.Vertexes[0].Location.X; mov.Fin.Y = pi.Vertexes[0].Location.Y; mov.Fin.Z = pi.Elevation; //movs.Add(Metodos.IrA(pi.Vertexes[i - 1].Location.X, pi.Vertexes[i - 1].Location.Y, pi.Elevation)); movs.Add(mov.ToString()); } //movs.Add("</polilinea>"); } return movs; }
public List<IEntidadObjeto> GenerarPolilineas(List<IEntidadObjeto> lista) { List<IEntidadObjeto> nuevaLista = new List<IEntidadObjeto>(); List<IEntidadObjeto> lineas = new List<IEntidadObjeto>(); //pasamos directo todas las figuras que NO son lineas for (int i = 0; i < lista.Count; i++) { if (lista[i].Tipo != EntidadTipo.Linea) nuevaLista.Add(lista[i]); else lineas.Add(lista[i]); } int sgteId = 0; int actualId; bool encontre = false; Polilinea poli = null; while (lineas.Count > 0) { encontre = false; actualId = sgteId; IEntidadObjeto linea = lineas[actualId]; lineas.RemoveAt(actualId); //buscamos otra "pegada" for (int i = 0; i < lineas.Count; i++) { if (Vector3f.Distance(linea.PFinal, lineas[i].PInicial) == 0) {//si el final de la linea coincide con el inicio de otra sgteId = i; encontre = true; break; } if(Vector3f.Distance(linea.PFinal, lineas[i].PFinal) == 0) {//si el final de la linea coincide con el fin de otra sgteId = i; encontre = true; //la "damos vuelta" lineas[sgteId].InvertirPuntos(); break; } } if (!encontre) {//sino encontramos otra linea "pegada" if (poli != null) {//si estabamos recorriendo una polilinea, entonces llegue al final //uso la polilinea y le agrego un vertice poli.Vertexes.Add(new PolylineVertex(linea.PInicial.X, linea.PInicial.Y)); poli.Vertexes.Add(new PolylineVertex(linea.PFinal.X, linea.PFinal.Y)); //si punto de inicio y fin coinciden, cerramos la polilinea if(Vector3f.Distance(new Vector3f(poli.Vertexes[0].Location.X,poli.Vertexes[0].Location.Y,poli.Elevation), new Vector3f(poli.Vertexes[poli.Vertexes.Count-1].Location.X,poli.Vertexes[poli.Vertexes.Count-1].Location.Y,poli.Elevation) ) == 0) poli.IsClosed=true; //agregamos la poli y la limpiamos nuevaLista.Add(poli); poli = null; } else {//es una linea aislada, la pasamos directo nuevaLista.Add(linea); } sgteId = 0; } else {//si encuentro otra linea "pegada" if (poli == null) {//creo una nueva polilinea poli = new Polilinea(); poli.Elevation = linea.PInicial.Z; } //uso la polilinea y le agrego un vertice poli.Vertexes.Add(new PolylineVertex(linea.PInicial.X, linea.PInicial.Y)); } } return nuevaLista; }