Author Topic: Transient code works in acad, not in bricscad  (Read 189 times)

0 Members and 1 Guest are viewing this topic.

jmaeding

  • Bull Frog
  • Posts: 286
  • How many of you have never raised your hand?
Transient code works in acad, not in bricscad
« on: September 27, 2017, 04:43:32 pm »
I did a test prog to draw a fence on screen as the user picks.
It works fine in autocad, but not in bricscad v16. I will try on V17 soon.

Here is the code, very typical of example routines that use point monitor.
What you should get is a red polyline being drawn, just like drawing a real pline.
Escape kills it, this is just an example prog.

Code: [Select]
//C# Usings
using System;
using System.Collections;
using SC = System.Collections;
using System.Collections.Generic;
using SCG = System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using SWF = System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Xml;
using System.Xml.Serialization;
using SM = System.Math;
using System.Linq;

//AutoCad Usings
#if ACAD
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.EditorInput;
using AcEd = Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcCo = Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Windows;
using AcWn = Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Customization;
#endif
#if BCAD
using Teigha.DatabaseServices;
using AcDb = Teigha.DatabaseServices;
using Bricscad.EditorInput;
using AcEd = Bricscad.EditorInput;
using Teigha.Geometry;
using AcGe = Teigha.Geometry;
using AcCo = Teigha.Colors;
using Teigha.Runtime;
using Teigha.GraphicsInterface;
using Bricscad.Runtime;
using Bricscad.ApplicationServices;
using AcAp = Bricscad.ApplicationServices.Application;
using Bricscad.Windows;
using AcWn = Bricscad.Windows;
#endif


[assembly: CommandClass(typeof(ProgTestingAcad.Program2))]

namespace ProgTestingAcad {

    public class Program2 {

        [CommandMethod("TESTPTS2")]
        public static void GetPts() {
            Document dwg = AcAp.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            MyptCmd cmd = new MyptCmd(dwg);
            cmd.GetPts();
        }
    }

    public class MyptCmd {
        private Document _dwg;
        private Editor _editor;

        private List<Point2d> _points;
        private List<Point2d> _origpoints = new List<Point2d>();
        private Point2d _resPt;
        private AcDb.Polyline _pline = null;

        public MyptCmd(Document dwg) {
            _dwg = dwg;
            _editor = _dwg.Editor;
        }

        public void GetPts() {

            _points = new List<Point2d>();

            //get first point
            PromptPointOptions opt = new PromptPointOptions("\nPick Point: ");
            PromptPointResult res = _editor.GetPoint(opt);
            if (res.Status == PromptStatus.OK) {
                _origpoints.Add(new AcGe.Point2d(res.Value.X, res.Value.Y));

                try {
                    //Handling mouse cursor moving during picking
                    _editor.PointMonitor += new PointMonitorEventHandler(_editor_PointMonitor);

                    bool loop = true;
                    //get more points
                    while (loop) {
                        if (!PickNewPoint())
                            loop = false; //no point
                        else
                            _origpoints.Add(_resPt);
                    }
                }
                catch {
                    throw;
                }
                finally {
                    ClearTransientGraphics();
                    //Remove PointMonitor handler
                    _editor.PointMonitor -= new PointMonitorEventHandler(_editor_PointMonitor);
                }
            }
        }

        private bool PickNewPoint() {
            PromptPointOptions opt = new PromptPointOptions("\nPick Point: ");
            PromptPointResult res = _editor.GetPoint(opt);

            if (res.Status == PromptStatus.OK) {
                _resPt = new AcGe.Point2d(res.Value.X, res.Value.Y);
                return true;
            }
            else {
                return false;
            }
        }

        private void ClearTransientGraphics() {
            TransientManager.CurrentTransientManager.EraseTransients(
                TransientDrawingMode.DirectShortTerm,
                128, new IntegerCollection());
            if (_pline != null)
                _pline.Dispose();
            _pline = null;
        }

        private void _editor_PointMonitor(object sender, PointMonitorEventArgs e) {
            ClearTransientGraphics();
            Point2d pt = new Point2d(e.Context.RawPoint.X, e.Context.RawPoint.Y);
            bool go = true;

            //figure new points
            //set _points to orig and add point
            //we must do this as we cannot simply add a point
            _points = new List<Point2d>();
            _points.AddRange(_origpoints);
            _points.Add(pt);

            //draw new _pline
            if (go) {
                _pline = new AcDb.Polyline(_points.Count);
                for (int i = 0; i < _points.Count; i++) {
                    _pline.AddVertexAt(i, _points[i], 0.0, 0.0, 0.0);
                }
                _pline.ColorIndex = 1;
                TransientManager.CurrentTransientManager.AddTransient(
                    _pline, TransientDrawingMode.DirectShortTerm, 128
                    , new IntegerCollection());
            }
        }

    }
}

Any ideas?
I tried directTopMost and other ideas, that did not matter.
thx
James Maeding

huiz

  • Swamp Rat
  • Posts: 775
  • Certified Prof C3D
Re: Transient code works in acad, not in bricscad
« Reply #1 on: September 27, 2017, 05:09:44 pm »
I noticed BricsCAD V17 does not update a transient entity during a PointMonitor, unless you scroll the mousewheel. Just static transient entities works fine.

The programmers in Gent are aware of it and will examine the possibilities.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

jmaeding

  • Bull Frog
  • Posts: 286
  • How many of you have never raised your hand?
Re: Transient code works in acad, not in bricscad
« Reply #2 on: September 27, 2017, 05:32:15 pm »
Nooooooooooooooo........
Shoot, I hit a bug?
I did a ton of programming in acad and have tried transients in bcad before so never thought they would misbehave in pointmonitor.
I hope they fix this.

Thanks for the heads up huiz!
James Maeding

huiz

  • Swamp Rat
  • Posts: 775
  • Certified Prof C3D
Re: Transient code works in acad, not in bricscad
« Reply #3 on: September 28, 2017, 03:57:12 am »
At least they take it more serious than another CAD software company  ;D
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

nullptr

  • BricsCAD
  • Needs a day job
  • Posts: 6735
  • AKA Daniel
Re: Transient code works in acad, not in bricscad
« Reply #4 on: September 28, 2017, 09:45:07 am »
hack alert
Code - C++: [Select]
  1.            if (go)
  2.            {
  3.                _pline = new AcDb.Polyline(_points.Count);
  4.                for (int i = 0; i < _points.Count; i++)
  5.                {
  6.                    _pline.AddVertexAt(i, _points[i], 0.0, 0.0, 0.0);
  7.                }
  8.                _pline.ColorIndex = 1;
  9.                TransientManager.CurrentTransientManager.AddTransient(
  10.                    _pline, TransientDrawingMode.DirectShortTerm, 128
  11.                    , new IntegerCollection());
  12.  
  13.                _editor.SetCurrentView(_editor.GetCurrentView());//<<<----
  14.            }
  15.  

edit: needs to be disposed so..

Code - C++: [Select]
  1.               using (ViewTableRecord rec = _editor.GetCurrentView())
  2.                {
  3.                    _editor.SetCurrentView(rec);
  4.                }
  5.  

there is probably a better alternative, this seems slightly laggy on large drawings


« Last Edit: September 28, 2017, 06:13:10 pm by nullptr »

jmaeding

  • Bull Frog
  • Posts: 286
  • How many of you have never raised your hand?
Re: Transient code works in acad, not in bricscad
« Reply #5 on: September 28, 2017, 01:28:26 pm »
'That is really amazing.' .... 'That really is truly amazing. That is so amazingly amazing I think I'd like to steal it.' -Zaphod Beeblebrox

It works, that was too easy! Thanks a TON for your reply, now my Bricscad stuff works perfect, I owe you!
James Maeding

huiz

  • Swamp Rat
  • Posts: 775
  • Certified Prof C3D
Re: Transient code works in acad, not in bricscad
« Reply #6 on: October 03, 2017, 07:51:03 am »
Indeed, perfect! In the AutoCAD variant I did not set the Current View, it works fine that way. If I add the SetCurrentView to the code it works as well in BricsCAD in a PointMonitor!

Sorry James that I incorrectly informed you, I was not aware of the brilliant solution!  :mrgreen:
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

jmaeding

  • Bull Frog
  • Posts: 286
  • How many of you have never raised your hand?
Re: Transient code works in acad, not in bricscad
« Reply #7 on: October 03, 2017, 11:07:38 am »
Huiz, you were right that bricsys is working on it, they told me also.
I also added a #if BCAD...statement to just run for bcad.

The use of transients like this is going to change so many tools I have done.
I used to use grdraw but that is archaic compared to transients.
James Maeding