Пример #1
0
 public static StreamViewModel ToViewModel(Stream stream, double progress = 1d) => new StreamViewModel()
 {
     streamName = stream.name,
     streamID   = stream.id,
     status     = "",
     streamDesc = stream.description,
     progress   = progress,
 };
Пример #2
0
 private void AddReceiver(Stream stream, Receiver receiver)
 {
     element.AddReceiver(
         viewModel: ToViewModel(stream),
         OnHide: () => manager.HideReceiver(receiver),
         OnUpdate: () => manager.Receive(receiver),
         OnRemove: () => manager.RemoveReceiver(receiver)
         );
 }
        private Receiver CreateReceiver(SpeckleStream stream, Transform parent, bool autoReceive, bool deleteOld)
        {
            string     streamID         = stream.id;
            GameObject streamGameObject = Instantiate(streamParentPrefab, Vector3.zero, Quaternion.identity, parent);

            streamGameObject.name = $"Receiver-{streamID}";

            Receiver receiver = streamGameObject.AddComponent <Receiver>();

            receiver.Init(streamID, autoReceive, deleteOld,
                          onDataReceivedAction: (go) =>
            {
                // when the stream has finished being received
                go.transform.parent = receiver.transform;

                {     //Dissable revit group objects
                    Transform room = go.transform.Find("@Rooms");
                    if (room)
                    {
                        room.gameObject.SetActive(false);
                    }
                    Transform model = go.transform.Find("@Model Groups");
                    if (model)
                    {
                        model.gameObject.SetActive(false);
                    }
                }

                Debug.Log($"Finished receiving {stream}");
                busyReceivers.RemoveItem(receiver);
                HideReceiver(receiver, true);
                OnStreamReceived?.Invoke(stream, receiver);
            },
                          onTotalChildrenCountKnown: (count) => { receiver.TotalChildrenCount = count; },
                          onProgressAction: (dict) =>
            {
                //Run on a dispatcher as GOs can only be retrieved on the main thread
                Dispatcher.Instance().Enqueue(() =>
                {
                    //When a part of the model has been received.
                    double val = dict.Values.Average() / receiver.TotalChildrenCount;
                    OnReceiverUpdate?.Invoke(stream, receiver, val);
                });
            });



            return(receiver);
        }
        /// <summary>
        /// Creates a new <see cref="Receiver"/> for a specified <paramref name="stream"/>
        /// </summary>
        /// <param name="stream">The <see cref="SpeckleStream"/> to be associated with the <see cref="Receiver"/></param>
        /// <param name="receiveNow">When True, the <see cref="Receiver"/> will start receiving once it has been created</param>
        /// <param name="autoReceive">When True, the <see cref="Receiver"/> will automatically receive updates</param>
        /// <param name="deleteOld">When True, the old <see cref="SpeckleStream"/> data will be remove on <see cref="Receiver.Receive"/></param>
        /// <returns>True if the <see cref="Receiver"/> was successfully added to the <see cref="ImportManager"/></returns>
        public bool CreateReceiver(SpeckleStream stream, bool receiveNow = true, bool autoReceive = false, bool deleteOld = true)
        {
            Receiver receiver = CreateReceiver(stream, parent, autoReceive, deleteOld);

            if (RegisterExisting(receiver))
            {
                if (receiveNow)
                {
                    Receive(receiver);
                }

                return(true);
            }

            Destroy(receiver.gameObject);
            return(false);
        }
        /// <summary>
        /// Adds a <paramref name="receiver"/> to the <see cref="ImportManager"/>
        /// </summary>
        /// <param name="receiver">The receiver to be added</param>
        /// <returns>true if the receiver was successfully added</returns>
        public bool RegisterExisting(Receiver receiver)
        {
            string streamID = receiver.StreamId;

            if (Receivers.ContainsKey(streamID))
            {
                Debug.LogWarning($"Failed to add {typeof(Receiver)} because one already existed for {nameof(streamID)}:{streamID}");
                return(false);
            }

            if (!StreamFromID.ContainsKey(streamID))
            {
                Debug.LogWarning($"Failed to add {typeof(Receiver)} because no {typeof(SpeckleStream)} with {nameof(streamID)}:{streamID} could be found");
                return(false);
            }

            SpeckleStream stream = StreamFromID[streamID];


            Receivers.Add(streamID, receiver);
            OnReceiverAdd?.Invoke(stream, receiver);

            return(true);
        }
Пример #6
0
 private void VisiblityChange(Stream stream, Receiver receiver) => VisiblityChange(ToViewModel(stream), receiver);
Пример #7
0
 private void RemoveReceiver(Stream stream, Receiver receiver = null) => RemoveReceiver(ToViewModel(stream));
Пример #8
0
 private void UpdateReceiver(Stream stream, Receiver receiver, double progress) => UpdateReceiver(ToViewModel(stream), receiver, progress);
Пример #9
0
 private void StreamReceived(Stream stream, Receiver receiver = null) => StreamReceived(ToViewModel(stream));