Profile Picture

How to remove artifacts after remove connection line?

Posted By Maxim Dobryakov 13 Years Ago
Author
Message
Maxim Dobryakov
questionmark Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 3, Visits: 1
Hello, All

I have implemented functionality to remove connection between two shapes in some cases (see EventSinkServiceOnConnected method in demo project). But it code cause creation of artifacts (see attached picture).

How to remove these artifacts after remove connection line?

For any case I have attached demo project to reproduce problem (rename file before extract from ZIP archive). Just try to connect two shapes to reproduce problem.

Thanks

Attachments
artifacts.png (100 views, 12.00 KB)
Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi,

The best approach for your scenario is to subscribe to the NodeInserted event of the document’s event sink service, add the created connectors to a list and use a timer to delete those of them you do not need. The following is a simple source code:

 

public MainForm()

{

      // Your initializing code here

      InitializeComponent();

m_Connectors = new List<NRoutableConnector>();

...

 

      // Subscribe to the NodeInserted event

ctlDrawingDocument.EventSinkService.NodeInserted += new ChildNodeEventHandler(EventSinkService_NodeInserted);

 

      // Initialize the timer

      m_Timer = new Timer();

      m_Timer.Interval = 100;

      m_Timer.Tick += new EventHandler(Timer_Tick);

}

 

private void EventSinkService_NodeInserted(NChildNodeEventArgs args)

{

      NRoutableConnector connector = args.Child as NRoutableConnector;

      if (connector != null)

      {

            m_Connectors.Add(connector);

            if (m_Timer.Enabled == false)

            {

                  // Start the processing timer if it is stopped

                  m_Timer.Start();

            }

      }

}

 

private void Timer_Tick(object sender, System.EventArgs e)

{

      // Evaluate the connectors and remove one or more of them based on your logic

      for (int i = 0, count = m_Connectors.Count; i < count; i++)

      {

            NRoutableConnector connector = (NRoutableConnector)m_Connectors[i];

            ctlDrawingDocument.ActiveLayer.RemoveChild(connector);

      }

 

      // Clear the processed connectors and stop the timer

      m_Connectors.Clear();

      m_Timer.Stop();

}



Best Regards,
Nevron Support Team



Maxim Dobryakov
Posted 13 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 3, Visits: 1
Hello,

Could you please explain hack with Timer? As I understand you use it for postpone removing.

How do you think is it possible to solve problem without timer? It will do my code more unclear.

Thanks



Similar Topics


Reading This Topic