Exemple #1
0
        public GroupViewModel CreateGroupRender(IGroup targetGroup, CompositeCommand cmds = null)
        {
            //create group element
            GroupViewModel NewGroupVM = WidgetFactory.CreateGroup(targetGroup) as GroupViewModel;

            //remove the older inner group
            List <GroupViewModel> AllGroups = items.OfType <GroupViewModel>().Where(c => c.IsGroup == true).ToList <GroupViewModel>();

            foreach (GroupViewModel it in AllGroups)
            {
                if (NewGroupVM.IsChild(it.widgetGID, true))
                {
                    it.IsSelected = false;
                    _selectionService.RemoveWidget(it);
                    items.Remove(it);
                }
            }


            //initialize all elements in new group
            foreach (WidgetViewModBase wdg in Items)
            {
                if (true == NewGroupVM.IsChild(wdg.widgetGID, false))
                {
                    wdg.ParentID   = NewGroupVM.widgetGID;
                    wdg.IsGroup    = false;
                    wdg.IsSelected = false;
                    NewGroupVM.AddChild(wdg);
                }
            }

            #region Reset Zorder

            // We got a crash report which was caused by  the exception System.InvalidOperationException from
            // System.Linq.Enumerable.Max(System.Collections.Generic.IEnumerable`1<Int32>), so make sure WidgetChildren has element first.
            // See http://bts1.nhncorp.com/nhnbts/browse/DSTUDIO-1679
            SetTargetObject2Front(NewGroupVM.WidgetChildren, cmds);
            //SetGroupTargetObjectContinue(, cmds, NewGroupVM);

            #endregion

            //UI Render the new group
            NewGroupVM.IsSelected = true;
            NewGroupVM.Status     = GroupStatus.Selected;
            //NewGroupVM.ZOrder = -3;
            Items.Add(NewGroupVM);
            NewGroupVM.Refresh();

            _ListEventAggregator.GetEvent <GroupChangedEvent>().Publish(true);
            return(NewGroupVM);
        }
Exemple #2
0
        private void RotateThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            //Initialize the selected widgets' context when first rotate
            if (_infoItems.Count <= 0)
            {
                WidgetViewModBase wdg = designerItem.DataContext as WidgetViewModBase;
                if (wdg.IsGroup == false)
                {
                    wdg.CreateNewPropertyMementos();
                    wdg.PropertyMementos.AddPropertyMemento(new PropertyMemento("RotateAngle", wdg.RotateAngle, wdg.RotateAngle));
                    _infoItems.Add(wdg);
                }
                else
                {
                    foreach (WidgetViewModBase item in (wdg as GroupViewModel).WidgetChildren)
                    {
                        item.CreateNewPropertyMementos();

                        item.CreateNewPropertyMementos();

                        item.PropertyMementos.AddPropertyMemento(new PropertyMemento("RotateAngle", item.RotateAngle, item.RotateAngle));
                        item.PropertyMementos.AddPropertyMemento(new PropertyMemento("Left", item.Raw_Left, item.Raw_Left));
                        item.PropertyMementos.AddPropertyMemento(new PropertyMemento("Top", item.Raw_Top, item.Raw_Top));
                        _infoItems.Add(item);
                    }
                }
            }

            //Rotate the current widget
            if (this.designerItem != null && this.canvas != null)
            {
                ContentPresenter wrapper = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(designerItem)) as ContentPresenter;

                Point  currentPoint = Mouse.GetPosition(this.canvas);
                Vector deltaVector  = Point.Subtract(currentPoint, this.centerPoint);

                double angle = Vector.AngleBetween(this.startVector, deltaVector);

                RotateTransform rotateTransform = designerItem.RenderTransform as RotateTransform;
                angle = this.initialAngle + Math.Round(angle, 0);



                if (angle < 0)
                {
                    angle += 360;
                }
                else if (angle >= 360)
                {
                    angle -= 360;
                }


                wrapper.InvalidateMeasure();

                if (this.designerItem.IsGroup == true)
                {
                    GroupViewModel group = this.designerItem.DataContext as GroupViewModel;

                    DesignerCanvas dc = canvas as DesignerCanvas;

                    foreach (WidgetViewModBase item in group.WidgetChildren)
                    {
                        RotateTransform rt = new RotateTransform(); // bw.RenderTransform as RotateTransform;
                        rt.Angle   = angle - groupIntialAngle;
                        rt.CenterX = groupCenterX;
                        rt.CenterY = groupCenterY;

                        double oldAngle = item.RotateAngle;
                        item.RotateAngle = Convert.ToInt16(angle - groupIntialAngle);
                        Rect rect1 = rt.TransformBounds(new Rect(item.Left, item.Top, item.ItemWidth, item.ItemHeight));
                        Rect rect2 = item.RevertBoundingRectangle(rect1);

                        //item.IsActual = true;
                        item.Raw_Left = rect2.Left;
                        item.Raw_Top  = rect2.Top;

                        //only widget can rotate
                        if (item is WidgetRotateViewModBase)
                        {
                            int newAngle = Convert.ToInt16(oldAngle + (angle - groupIntialAngle)) % 360;
                            if (newAngle < 0)
                            {
                                newAngle += 360;
                            }
                            else if (angle >= 360)
                            {
                                newAngle -= 360;
                            }
                            item.RotateAngle = newAngle;
                        }
                        else
                        {
                            item.RotateAngle = 0;
                        }
                    }

                    group.Refresh();
                    groupIntialAngle = angle;
                }
                else
                {
                    rotateTransform.Angle = angle;
                }


                if (this.designerItem.ParentID != Guid.Empty)
                {
                    IGroupOperation pageVM = canvas.DataContext as IGroupOperation;
                    pageVM.UpdateGroup(this.designerItem.ParentID);
                }

                if (this.designerItem.IsGroup)
                {
                    IGroupOperation pageVM = canvas.DataContext as IGroupOperation;
                    pageVM.UpdateGroup((this.designerItem.DataContext as GroupViewModel).WidgetID);
                }
            }
        }