Example #1
0
        public void draw()
        {
            ObjectId  layerId = LayerUtil.CreateLayer("coordinate", 0, false);
            Extents3d bounds  = MyDBUtility.getExtents(mydb.getAllLine());

            double zlen = 0;
            double minz = -10;

            if (mydb.TEDicList.Count > 0)
            {
                TEDictionary ted = mydb.TEDicList[0];
                zlen  = ted.maxMaxZ - ted.minMaxZ;
                zlen += 10;
                minz  = ted.minMaxZ - 5;
            }


            Point3d ori = bounds.MinPoint.Add(new Vector3d(-10, -10, 0));

            ori = ori.Add(new Vector3d(0, 0, (minz - ori.Z)));
            double xlen = bounds.MaxPoint.X - bounds.MinPoint.X + 20;
            double ylen = bounds.MaxPoint.Y - bounds.MinPoint.Y + 20;

            MyDBUtility.line(ori, new Point3d(ori.X + xlen, ori.Y, ori.Z), layerId);
            MyDBUtility.line(ori, new Point3d(ori.X, ori.Y + ylen, ori.Z), layerId);
            Point3d zstart = ori.Add(new Vector3d(0, ylen, 0));
            Point3d zend   = zstart.Add(new Vector3d(0, 0, zlen));

            MyDBUtility.line(zstart, zend, layerId);
            int xcount = (int)xlen / 10;
            int ycount = (int)ylen / 10;
            int zcount = (int)zlen / 5;

            for (int i = 0; i < xcount; i++)
            {
                Point3d s = ori.Add(new Vector3d(i * 10, 0, 0));
                Point3d e = s.Add(new Vector3d(0, -5, 0));
                MyDBUtility.line(s, e, layerId);
                MyDBUtility.text(e, ((int)s.X).ToString(), -Math.PI / 2, layerId);
            }
            for (int i = 0; i < ycount; i++)
            {
                Point3d s = ori.Add(new Vector3d(0, i * 10, 0));
                Point3d e = s.Add(new Vector3d(-5, 0, 0));
                MyDBUtility.line(s, e, layerId);
                MyDBUtility.text(e.Add(new Vector3d(-5, 0, 0)), ((int)s.Y).ToString(), 0, layerId);
            }

            for (int i = 0; i < zcount; i++)
            {
                Point3d s = ori.Add(new Vector3d(0, ylen, i * 5));
                Point3d e = s.Add(new Vector3d(0, 5, 0));
                MyDBUtility.line(s, e, layerId);
                MyDBUtility.text(e.Add(new Vector3d(0, 10, 0)), ((int)s.Z).ToString(), 0, layerId);
            }
        }
Example #2
0
 public void decreaseResolution()
 {
     if (Resolution < 0)
     {
         Resolution = 0;
     }
     LayerUtil.setLayerProp(getFaceLayerName(), true);
     Resolution--;
     LayerUtil.setLayerProp(getFaceLayerName(), false);
 }
Example #3
0
        public void increasePoint()
        {
            LayerUtil.setLayerProp(mydb.getFaceLayerName(), true);
            mydb.increaseResolution();
            if (LayerUtil.hasName(mydb.getFaceLayerName()))
            {
            }
            else
            {
                tri();
            }

            LayerUtil.setLayerProp(mydb.getFaceLayerName(), false);
        }
Example #4
0
 public void decreasePoint()
 {
     LayerUtil.setLayerProp(mydb.getFaceLayerName(), true);
     mydb.decreaseResolution();
     LayerUtil.setLayerProp(mydb.getFaceLayerName(), false);
 }
Example #5
0
        public void tri()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                ObjectId   boundaryLayerId = LayerUtil.CreateLayer(boundaryLayerName, 127, false);
                PointSet   ps       = mydb.getAllPoint();
                ObjectId[] ids      = mydb.LineIds;
                ObjectId[] bidArray = Selection.getBoundarys();

                List <ObjectId> boundaryIds = null;
                if (bidArray == null || bidArray.Length <= 0)
                {
                    boundaryIds = new List <ObjectId>();
                }
                else
                {
                    boundaryIds = bidArray.ToList();
                }

                if (boundaryIds.Count <= 0)
                {
                    List <Point3d> pl = PreProcess.getOuterBoundaryFromLine(ids, null);
                    //List<ObjectId> plineIds = new List<ObjectId>();

                    ObjectId?plineId = MyDBUtility.addPolyline3d(pl, boundaryLayerId, true);

                    if (plineId != null)
                    {
                        boundaryIds.Add(plineId.Value);
                    }
                    List <Edge> el = MyConvert.ToEdgeList(pl);
                    if (el == null)
                    {
                        ed.WriteMessage("\nel==null");
                    }

                    for (int i = 0; i < el.Count; i++)
                    {
                        //boundary.Add(new Constraint(el[i], Constraint.ConstraintType.Boundary));
                    }
                    List <Point3d> pl2      = this.getInnerBo(ids);
                    ObjectId?      plineId2 = MyDBUtility.addPolyline3d(pl2, boundaryLayerId, true);
                    if (plineId2 != null)
                    {
                        boundaryIds.Add(plineId2.Value);
                    }
                    List <Edge> el2 = MyConvert.ToEdgeList(pl);
                    if (el2 == null)
                    {
                        ed.WriteMessage("\nel2==null");
                    }
                    else
                    {
                        for (int i = 0; i < el2.Count; i++)
                        {
                            //boundary.Add(new Constraint(el2[i], Constraint.ConstraintType.Boundary));
                        }
                    }
                }
                else
                {
                }
                List <Constraint> boundary = new List <Constraint>();
                List <Edge>       list4    = Conversions.ToCeometricEdgeList(boundaryIds.ToArray());
                for (int j = 0; j < list4.Count; j++)
                {
                    boundary.Add(new Constraint(list4[j], Constraint.ConstraintType.Boundary));
                }

                Triangulate tri = new Triangulate();
                //tri.TriangulateInternal(ps, new List<Constraint>(), new List<Constraint>());
                LayerUtil.setLayerProp(mydb.getFaceLayerName(), false);
                List <Triangle> tris = tri.TriangulateInternal(ps, new List <Constraint>(), boundary, mydb.getFaceLayerName());
                mydb.setTris(tris);
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage("UserCmd 144 " + ex.Message);
            }
        }
Example #6
0
        public static void WriteListInDatabase <T>(List <T> entities, CoordinateSystem acutalCS, DBManager.EntityPropertiesAssignment propertyAssignmentMethod, ObjectId layerID, ObjectId blockID, string layerName)
        {
            if (entities != null && entities.Count != 0)
            {
                Database      workingDatabase = HostApplicationServices.WorkingDatabase;
                Editor        editor          = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
                ProgressMeter progressMeter   = new ProgressMeter();
                MessageFilter messageFilter   = new MessageFilter();
                System.Windows.Forms.Application.AddMessageFilter(messageFilter);

                List <Triangle> triList = new List <Triangle>();

                try
                {
                    blockID = SymbolUtilityServices.GetBlockModelSpaceId(workingDatabase);
                    if (layerName != null)
                    {
                        layerID = LayerUtil.CreateLayer(layerName, 127, false);
                    }
                    else
                    {
                        layerID = ObjectId.Null;
                    }

                    if (typeof(T) != typeof(Triangle))
                    {
                        throw new NotImplementedException("Generic list type not supported: " + typeof(T).ToString());
                    }

                    triList = (List <Triangle>)Convert.ChangeType(entities, typeof(List <Triangle>));

                    if (acutalCS != null)
                    {
                        Conversions.ToWCS(acutalCS, triList);
                    }
                    progressMeter.SetLimit(entities.Count);
                    progressMeter.Start("Writing database");
                    using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction())
                    {
                        LayerTable       layerTable       = (LayerTable)transaction.GetObject(workingDatabase.LayerTableId, (OpenMode)0);
                        BlockTable       blockTable       = (BlockTable)transaction.GetObject(workingDatabase.BlockTableId, (OpenMode)0);
                        BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockID, (OpenMode)1);
                        for (int i = 0; i < entities.Count; i++)
                        {
                            Autodesk.AutoCAD.Colors.Color color = null;
                            short   colorIndex = 256;
                            Point3d point3d3   = new Point3d(triList[i].Vertex1.X, triList[i].Vertex1.Y, triList[i].Vertex1.Z);

                            Point3d point3d4 = new Point3d(triList[i].Vertex2.X, triList[i].Vertex2.Y, triList[i].Vertex2.Z);

                            Point3d point3d5 = new Point3d(triList[i].Vertex3.X, triList[i].Vertex3.Y, triList[i].Vertex3.Z);

                            Entity entity = new Autodesk.AutoCAD.DatabaseServices.Face(point3d3, point3d4, point3d5, true, true, true, true);

                            if (layerID != ObjectId.Null)
                            {
                                entity.LayerId = (layerID);
                            }

                            if (color == null)
                            {
                                entity.ColorIndex = ((int)colorIndex);
                            }
                            else
                            {
                                entity.Color = (color);
                            }
                            blockTableRecord.AppendEntity(entity);
                            transaction.AddNewlyCreatedDBObject(entity, true);
                            progressMeter.MeterProgress();
                            messageFilter.CheckMessageFilter((long)i, 10000);
                        }

                        transaction.Commit();
                    }

                    progressMeter.Stop();
                    editor.WriteMessage(Environment.NewLine + entities.Count.ToString() + " entities written to database.");
                    editor.WriteMessage("\n");
                    editor.Regen();
                    return;
                }
                catch
                {
                    progressMeter.Stop();
                    throw;
                }
            }
            throw new System.Exception("No entities written in database.");
        }