Bevisuali.Model.Workbench.ThreadMainNetworkLayout C# (CSharp) Method

ThreadMainNetworkLayout() protected method

protected ThreadMainNetworkLayout ( ) : void
return void
        protected void ThreadMainNetworkLayout()
        {
            while (true)
            {
                if (_networkLayoutThreadCancel)
                {
                    break;
                }

                bool didWork = false;

                // Grab a reference to the record for our operation.
                NetworkLayoutRecord record = this._networkLayoutInternal;
                var algorithm = record.AlgorithmState;

                // If there is work to do.
                if (record != null
                    && record.AlgorithmState.IterationCount < record.Options.Iterations)
                {
                    // Mark as computing.
                    record.NetworkLayout.ComputationState = ComputationState.Computing;

                    // Compute.
                    algorithm.RefineLayout(NetworkLayoutIterationChunkSize);

                    // Publish results.
                    record.NetworkLayout.Positions = algorithm.Positions;

                    // Raise event for one large step finished.
                    if (NetworkLayoutUpdated != null)
                    {
                        NetworkLayoutUpdated(this);
                    }

                    // Update record step count.
                    didWork = true;
                }
                // We're finished. Mark done.
                else if (record.AlgorithmState.IterationCount == record.Options.Iterations
                    && record.NetworkLayout.ComputationState != ComputationState.Done)
                {
                    record.NetworkLayout.ComputationState = ComputationState.Done;
                }

                if (_networkLayoutThreadCancel)
                {
                    break;
                }

                if (!didWork)
                {
                    Thread.Sleep(200);
                }
            }
        }