Ejemplo n.º 1
0
        private void ComponentBox_ItemSelected(object sender, ComponentBoxItemModel model)
        {
            if (!IsComponentBoxOpen)
            {
                return;
            }

            // Close Opened Box
            CloseComponentBox();

            // Create Component
            FrameworkElement visual         = AddNewComponent(model, this.PointFromScreen(componentBoxPosition));
            IRenderer        targetRenderer = visual.GetRenderer();

            // * Logic Binding *
            PBinder outputBinder = null;
            PBinder inputBinder  = null;

            // Component -> Component
            if (componentBox.TargetObject is BindRequest request)
            {
                var         host       = request.Source.Binder.Host as PBinderHost;
                IRenderer   renderer   = host.GetRenderer();
                IBinderHost targetHost = targetRenderer.ProvideValue();

                PBinder sourceBinder = request.Source.Binder;
                PBinder targetBinder = targetHost.GetConnectableBinders(sourceBinder).FirstOrDefault() as PBinder;

                if (sourceBinder == null || targetBinder == null)
                {
                    // 연결 실패
                    return;
                }

                BinderHelper.GetPairObject(
                    ref outputBinder, ref inputBinder,
                    (sourceBinder, sourceBinder.BindOption),
                    (targetBinder, targetBinder.BindOption));
            }

            // Layout -> Component
            if (componentBox.TargetObject is PObject pObj)
            {
                IRenderer renderer = pObj.GetRenderer();

                outputBinder = renderer.ProvideValue()[BindOptions.Output].FirstOrDefault() as PBinder;
                inputBinder  = targetRenderer.ProvideValue()[BindOptions.Input].FirstOrDefault() as PBinder;
            }

            if (outputBinder == null || inputBinder == null)
            {
                // 연결 실패
                return;
            }

            ConnectComponent(
                outputBinder.GetView <BindThumb>(),
                inputBinder.GetView <BindThumb>());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 로직 컴포넌트를 생성합니다.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        public FrameworkElement AddNewComponent(ComponentBoxItemModel model, Point position)
        {
            Type pType = model.ItemModelType;

            if (pType == null)
            {
                MessageBox.Show("Coming soon! (Logic)");
                return(null);
            }

            var metadata = DesignerManager.GetElementType(pType);
            var control  = this.GenerateToElement(this, metadata.Element, position) as ComponentElement;

            // Trigger Setting
            if (model.ComponentType == ComponentType.Event)
            {
                var triggerRenderer = control.GetRenderer() as TriggerRenderer;

                triggerRenderer.Model.SetRuntimeEvent(model.Data as EventInfo);
            }

            // Selector Setting
            if (model.ComponentType == ComponentType.Instance)
            {
                var selectorRenderer = control.GetRenderer() as SelectorRenderer;

                selectorRenderer.Model.Title        = model.Title;
                selectorRenderer.Model.TargetVisual = model.Data as PVisual;
            }

            // Function Setting
            if (model.ComponentType == ComponentType.Function)
            {
                var functionRenderer = control.GetRenderer() as FunctionRenderer;

                functionRenderer.Model.SetRuntimeFunction(model.Data as MethodInfo);
            }

            ZoomFocusTo(control.GetRenderer());

            return(control);
        }
Ejemplo n.º 3
0
 public ComponentBoxItemView(ComponentBoxItemModel model)
 {
     this.DataContext = model;
 }