Esempio n. 1
0
        public static void EditWindow(ObjectId groupId)
        {
            Document doc    = AcAp.Application.DocumentManager.MdiActiveDocument;
            Database db     = doc.Database;
            Group    group  = null;
            Ballon   ballon = null;

            using (Transaction acTrans = db.TransactionManager.StartTransaction())
            {
                try
                {
                    group = acTrans.GetObject(groupId, OpenMode.ForWrite) as Group;
                    acTrans.Commit();
                }
                catch (System.Exception)
                {
                    acTrans.Abort();
                }
            }

            if (group != null)
            {
                ballon = ReadBallonFromBuffer(group.XData);
                ViewBallon      viewBallon      = new ViewBallon();
                BallonViewModel ballonViewModel = new BallonViewModel();
                ballonViewModel.BallonObjectId = groupId;
                ballonViewModel.MyBallon       = ballon;
                viewBallon.DataContext         = ballonViewModel;
                ballonViewModel.GetData        = new RelayCommand(EditDataInvoke);
                ballonViewModel.Layers         = DatabaseHelper.GetAllLayerFromCad();
                AcAp.Application.ShowModalWindow(viewBallon);
            }
        }
Esempio n. 2
0
        private static void EditBallon(BallonViewModel ballonViewModel)
        {
            Document    doc   = AcAp.Application.DocumentManager.MdiActiveDocument;
            Database    db    = doc.Database;
            Transaction trans = doc.TransactionManager.StartTransaction();

            using (trans)
            {
                try
                {
                    Group      group     = trans.GetObject(ballonViewModel.BallonObjectId, OpenMode.ForWrite) as Group;
                    ObjectId[] objectIds = group.GetAllEntityIds();
                    Line       line      = null;
                    Circle     circle    = null;
                    DBText     dBText    = null;
                    foreach (ObjectId item in objectIds)
                    {
                        DBObject ent = trans.GetObject(item, OpenMode.ForWrite);
                        if (ent is Line)
                        {
                            line = ent as Line;
                        }
                        else if (ent is Circle)
                        {
                            circle = ent as Circle;
                        }
                        else if (ent is DBText)
                        {
                            dBText = ent as DBText;
                        }
                    }
                    //edit graphical properties for ballon
                    dBText.TextString = ballonViewModel.StringInput;
                    double newLenth  = ballonViewModel.Length;
                    double newRadian = ballonViewModel.Angle * Math.PI / 180;
                    line.EndPoint   = new Point3d(line.StartPoint.X + newLenth * Math.Cos(newRadian), line.StartPoint.Y + newLenth * Math.Sin(newRadian), line.StartPoint.Z);
                    line.Layer      = ballonViewModel.LayerName;
                    line.ColorIndex = ballonViewModel.ColorIndex;
                    double newRadius = ballonViewModel.Radius;
                    circle.Radius         = newRadius;
                    circle.Center         = new Point3d(line.EndPoint.X + newRadius * Math.Cos(newRadian), line.EndPoint.Y + newRadius * Math.Sin(newRadian), line.EndPoint.Z);
                    dBText.AlignmentPoint = circle.Center;
                    //edit xdata
                    ResultBuffer rb = CreateBalloonBuffer(ballonViewModel.MyBallon, BALLON_XDATA_NAME);
                    group.XData = rb;// new ResultBuffer(new TypedValue(1001, BALLON_XDATA_NAME));
                    rb.Dispose();
                    trans.Commit();
                }
                catch (Exception e)
                {
                    trans.Abort();
                    throw e;
                }
            }
        }
Esempio n. 3
0
        private void GetDataInvoke(object obj)
        {
            Window          wnd    = obj as Window;
            BallonViewModel result = wnd.DataContext as BallonViewModel;

            if (result != null)
            {
                string error = string.Empty;
                if (result.Validate(ref error))
                {
                    wnd.Close();
                    CreateAndGroupBallon(result.MyBallon);
                }
                else
                {
                    MessageBox.Show(error);
                }
            }
        }
Esempio n. 4
0
        private static void EditDataInvoke(object obj)
        {
            Window          wnd             = obj as Window;
            BallonViewModel ballonViewModel = wnd.DataContext as BallonViewModel;

            if (ballonViewModel != null)
            {
                string error = string.Empty;
                if (ballonViewModel.Validate(ref error))
                {
                    EditBallon(ballonViewModel);
                    wnd.Close();
                }
                else
                {
                    MessageBox.Show(error);
                }
            }
        }
Esempio n. 5
0
 public void ShowWindow()
 {
     try
     {
         ViewBallon      viewBallon      = new ViewBallon();
         BallonViewModel ballonViewModel = new BallonViewModel();
         ballonViewModel.GetData = new RelayCommand(GetDataInvoke);
         viewBallon.DataContext  = ballonViewModel;
         ballonViewModel.Layers  = DatabaseHelper.GetAllLayerFromCad();
         if (ballonViewModel.Layers != null && ballonViewModel.Layers.Count > 0)
         {
             ballonViewModel.LayerName = ballonViewModel.Layers.ElementAt(0);
         }
         AcAp.Application.ShowModalWindow(viewBallon);
     }
     catch (Exception e)
     {
         AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(e.Message);
     }
 }