// public API for update UI
 public void SetHeatProducer(HeatProducer p)
 {
     selectedObject.SetHeatProducer(p, this);
     this.DataContext = selectedObject;
     _propertyGrid.Update();
 }
        //生成block预览
        //插入block
        public void Insertblock(string s, out bool status)
        {
            status = false;
            DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
            Database db = HostApplicationServices.WorkingDatabase;
            ObjectId spaceId = db.CurrentSpaceId;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            String promptText = s.Contains("锅炉") ? "\n 选择插入热源的位置" : "\n 选择插入热力站的位置";
            PromptPointOptions getPointOptions = new PromptPointOptions(promptText);
            getPointOptions.AppendKeywordsToMessage = true;
            PromptPointResult getPointResult = ed.GetPoint(getPointOptions);

            if(getPointResult.Status == PromptStatus.Cancel)
            {
                status = true;
                return;
            }
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                ObjectId layerid = HeatSourceLayoutApp.currentSolution.BaseObjectId;
                LayerTableRecord layer = trans.GetObject(layerid, OpenMode.ForWrite) as LayerTableRecord;
                ObjectId blockid = spaceId.InsertBlockReference(layer.Name, s, getPointResult.Value, new Scale3d(HeatSourceLayoutApp.globalProperty.BlockScale), 0);
                trans.Commit();
                //将新建的热力站/热源存入解决方案的对象中
                if (s.CompareTo("锅炉5吨") == 0)
                {
                    HeatProducer producer = new HeatProducer(HeatSourceLayoutApp.currentSolution, true);
                    producer.BaseObjectId = blockid;
                    producer.Save();
                    HeatSourceLayoutApp.currentSolution.HeatProducers.Add(blockid, producer);
                }
                else if (s.CompareTo("换热机组") == 0)
                {
                        SubStation station = new SubStation(HeatSource.HeatSourceLayoutApp.currentSolution, true);
                        station.BaseObjectId = blockid;
                        station.Save();
                        HeatSourceLayoutApp.currentSolution.SubStations.Add(blockid, station);
                 }
            }
        }
 public void SetHeatProducer(HeatProducer p, HeatProducerAttrEditor editor)
 {
     this.currentProducer = p;
     heatProducerAttrEditor = editor;
 }
 //管道总长度
 public double GetTotalPipeLengthOfModel(BaseModel model, out List <PipeLine> lines)
 {
     if (model is SubStation || model is HeatProducer)
     {
         List <PipeLine> connectedpipes = SearchConnected(model);
         List <PipeLine> pipes          = new List <PipeLine>();
         foreach (var item in connectedpipes)
         {
             if (model is HeatProducer)
             {
                 pipes.Add(item);
             }
             else if (model is SubStation)
             {
                 if (item.Style == PipeLineStyle.AnyConnectedBuilding)
                 {
                     pipes.Add(item);
                 }
             }
         }
         double           total = 0;
         Stack <PipeLine> st    = new Stack <PipeLine>();
         foreach (var item in pipes)
         {
             st.Push(item);
         }
         Dictionary <ObjectId, PipeLine> allLines = new Dictionary <ObjectId, PipeLine>();
         while (st.Count != 0)
         {
             PipeLine pl = st.Pop();
             if (!allLines.ContainsKey(pl.BaseObjectId))
             {
                 allLines.Add(pl.BaseObjectId, pl);
                 if (pl.HeadConnectedObject != null)
                 {
                     foreach (var item in pl.HeadConnectedObject.ConnectedPipes)
                     {
                         if (!allLines.ContainsKey(item.BaseObjectId))
                         {
                             st.Push(item);
                         }
                     }
                 }
                 if (pl.TailConnectedObject != null)
                 {
                     foreach (var item in pl.TailConnectedObject.ConnectedPipes)
                     {
                         if (!allLines.ContainsKey(item.BaseObjectId))
                         {
                             st.Push(item);
                         }
                     }
                 }
             }
         }
         List <PipeLine> ConnectedLines = new List <PipeLine>();
         foreach (var item in allLines)
         {
             ConnectedLines.Add(item.Value);
             total += item.Value.CalculateLength();
         }
         lines = ConnectedLines;
         //
         if (model is HeatProducer)
         {
             HeatProducer heatProducer = (HeatProducer)model;
             if (heatProducer.OwnSlaveDistrict != null)
             {
                 foreach (var item in heatProducer.OwnSlaveDistrict.SubStations)
                 {
                     List <PipeLine> ls;
                     total += item.OwnSolution.GetTotalPipeLengthOfModel(item, out ls);
                     lines.AddRange(ls);
                 }
             }
         }
         return(total);
     }
     lines = new List <PipeLine>();
     return(0);
 }