public void DrawBall()
        {
            Ball ball = new Ball();

            ball.PlaceObject();
            McContext.ShowNotification("Use green grip or shake (move) ball to get prediction");
        }
        // added in v. 1.1
        private  void OnChanged(object source, FileSystemEventArgs e)
        {

            McContext.ShowNotification("File: " + e.FullPath + " " + e.ChangeType);
          
            //read new value from file
            try
            {

                if (File.Exists(_monFilePath))
                {
                    int mStatus = -1;
                    McContext.ShowNotification("File exists ");

                    using (StreamReader sr = new StreamReader(new FileStream(_monFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                    {
                        if (sr.BaseStream.CanRead)
                        {
                            McContext.ShowNotification("can read ");
                            if (int.TryParse(sr.ReadLine(), out mStatus))
                            {
                                McContext.ShowNotification("parse correct ");
                                if (Enum.IsDefined(typeof(Status), mStatus))
                                {

                                    if (!TryModify())  return;
                                    Stat = (Status) mStatus; 
                                    if (!TryModify()) return;
                                    if (!DbEntity.Update()) return;
                                    McContext.ShowNotification("Door state is changed");
                                    McContext.ExecuteCommand("REGENALL");
                                    

                                }
                                else McContext.ShowNotification("Incorrect data in the file. Should be in diapason: 0, 1, 2 ");
                            }

                        }
                        else McContext.ShowNotification("Can't read file ");
                    }

                }
                else McContext.ShowNotification("File not exists  ");



                _watcher.EnableRaisingEvents = false; // disable tracking
            }
            finally
            {
                _watcher.EnableRaisingEvents = true; // reconnect tracking
            }
          
        }
 public void StartMonitoring()
 {
     _watcher = new FileSystemWatcher();
     if (File.Exists(_monFilePath))
     {
         _watcher.Path = Path.GetDirectoryName(_monFilePath);
         _watcher.Filter = Path.GetFileName(_monFilePath);
         _watchHandler = new FileSystemEventHandler(OnChanged);
         _watcher.Changed += _watchHandler;
         _watcher.EnableRaisingEvents = true;
     }
     else McContext.ShowNotification("File: " + _monFilePath + " " + "not Exists");
 }
        public void DestroySPDSobjects(List <string> allDwgPath, bool isSaveDWG)
        {
            HostMgdApp.Application ncadMgpApp = Marshal.GetActiveObject("nanocad.Application") as HostMgdApp.Application;
            foreach (string oneDwg in allDwgPath)
            {
                HostMgdApp.Document docMgb;
                try
                {
                    docMgb = HostMgdApp.Application.DocumentManager.Open(oneDwg, false);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Ошибка: " + ex.Message);
                    return;
                }

                // spexplodeall разрушает все СПДС объекты
                McContext.ExecuteCommand("spexplodeall");
                System.Windows.Forms.SendKeys.SendWait("{ENTER}");// окно подтверждения

                // чтобы пользователь мог просмотреть изменения какие сделала команда
                // если isSaveDWG == true чертежи закрываются с сохранением

                if (isSaveDWG)
                {
                    mcObj.McDocument mcDocItem = mcObj.McDocument.ActiveDocument;

                    try
                    {
                        mcDocItem.Save();
                        mcDocItem.Close();
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show("Ошибка: " + ex.Message);
                        return;
                    }
                }
            }
        }
        // added in v. 1.1
        private void OnChanged(object source, FileSystemEventArgs e)
        {
            DocumentCollection dm = HostMgd.ApplicationServices.Application.DocumentManager;
            Editor             ed = dm.MdiActiveDocument.Editor;

            ed.WriteMessage("File: " + e.FullPath + " " + e.ChangeType);

            //read new value from file
            try
            {
                if (File.Exists(_monFilePath))
                {
                    int mStatus = -1;
                    ed.WriteMessage("File exists ");

                    using (StreamReader sr = new StreamReader(new FileStream(_monFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                    {
                        if (sr.BaseStream.CanRead)
                        {
                            if (int.TryParse(sr.ReadLine(), out mStatus))
                            {
                                if (Enum.IsDefined(typeof(Status), mStatus))
                                {
                                    if (!TryModify())
                                    {
                                        return;
                                    }
                                    Stat = (Status)mStatus; // преобразование
                                    if (!TryModify())
                                    {
                                        return;
                                    }
                                    DbEntity.Update();
                                    McContext.ExecuteCommand("REGENALL");
                                    ed.WriteMessage("Door state is changed");
                                }
                                else
                                {
                                    ed.WriteMessage("Incorrect data in the file. Should be in diapason: 0, 1, 2 ");
                                }
                            }
                        }
                        else
                        {
                            ed.WriteMessage("Can't read file ");
                        }
                    }
                }
                else
                {
                    ed.WriteMessage("File not exists  ");
                }



                _watcher.EnableRaisingEvents = false; // disable tracking
            }
            finally
            {
                _watcher.EnableRaisingEvents = true; // reconnect tracking
            }
        }
Example #6
0
        public void DrawFace()
        {
            //We draw half of face

            // Draw eye
            DbCircle eye = new DbCircle();

            eye.Radius = 100;
            eye.Center = new Point3d(200, 500, 0);
            eye.DbEntity.AddToCurrentDocument();

            //Draw nose
            DbLine nose = new DbLine();

            nose.StartPoint = new Point3d(350, 400, 0);
            nose.EndPoint   = new Point3d(350, 200, 0);
            nose.DbEntity.AddToCurrentDocument();

            //Draw mouth
            DbPolyline     mouth       = new DbPolyline();
            List <Point3d> mouthPoints = new List <Point3d>()
            {
                new Point3d(100, 150, 0), new Point3d(200, 100, 0), new Point3d(350, 100, 0)
            };

            mouth.Polyline = new Polyline3d(mouthPoints);
            mouth.Polyline.SetClosed(false);
            mouth.DbEntity.Transform(McDocumentsManager.GetActiveDoc().UCS); //change coordinates from UCS to WCS for BD
            mouth.DbEntity.AddToCurrentDocument();

            //draw mirror half the face (2nd half)

            DbCircle eye2 = new DbCircle();

            eye2.Radius = 100;
            eye2.Center = new Point3d(500, 500, 0);
            eye2.DbEntity.AddToCurrentDocument();

            DbPolyline mouth2 = new DbPolyline();

            mouth2.Polyline = mouth.Polyline.Mirror(new Plane3d(new Point3d(350, 100, 0), new Vector3d(200, 0, 0))) as Polyline3d;
            mouth2.DbEntity.AddToCurrentDocument();

            //Get notification in command line
            McContext.ShowNotification("You need to enter data into the console");


            //Get uaser input
            InputJig editorInput = new InputJig();
            string   name        = editorInput.GetText("Input your name and press Enter");

            //Drawing face's text
            DbText spech = new DbText();

            spech.Text = new TextGeom("Oh Master! Why I'm so ugly? Please remove me!", new Point3d(510, 15, 0), Vector3d.XAxis, "Standard", 15);
            spech.DbEntity.AddToCurrentDocument();


            //Get windows message box
            MessageBox.Show("Congratulation " + name + " you did it! But look, it want, to say something to you...");

            //Get popup help
            McContext.PopupNotification("Delete command has activated");

            //Activate another command (Delete)
            McContext.ExecuteCommand("Delete");
        }