Exemplo n.º 1
0
        private void ResizeClick(object sender, RoutedEventArgs e)
        {
            if (myHull.Bulkheads.Count == 0)
            {
                MessageBox.Show("Can't resize a non-existant hull.");
                return;
            }

            EditableHull hull = new EditableHull(myHull);

            Size3D originalSize = hull.GetSize();

            ResizeWindow resize = new ResizeWindow(hull);

            resize.ShowDialog();

            if (resize.OK)
            {
                ResizeWindowData resizeData = (ResizeWindowData)resize.FindResource("ResizeData");
                double           scale_x    = 1.0;
                double           scale_y    = 1.0;
                double           scale_z    = 1.0;

                if (resizeData != null)
                {
                    scale_x = resizeData.Width / originalSize.X;
                    scale_y = resizeData.Height / originalSize.Y;
                    scale_z = resizeData.Length / originalSize.Z;

                    myHull.Scale(scale_x, scale_y, scale_z);
                    UpdateViews();
                }
            }
        }
Exemplo n.º 2
0
        public ResizeWindow(EditableHull hull)
        {
            InitializeComponent();
            ResizeWindowData resizeData = (ResizeWindowData)this.FindResource("ResizeData");

            if (resizeData != null)
            {
                bool proportional = resizeData.Proportional;

                // Need to turn off Proportional for initial setup
                resizeData.Proportional = false;

                Size3D size = hull.GetSize();
                resizeData.Width        = size.X; // multiply by 2 because this is half-hull
                resizeData.Height       = size.Y;
                resizeData.Length       = size.Z;
                resizeData.Proportional = true;

                // Reset proportional
                resizeData.Proportional = proportional;
            }
        }
Exemplo n.º 3
0
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            m_RecreateHandles = false;
            Point loc = e.GetPosition(this);

            m_mouse_X = 0;
            m_mouse_Y = 0;
            m_mouse_Z = 0;

            Rect bounds = new Rect(new Size(0, 0));

            if (m_bulkheadGeometry.Count > 0)
            {
                bounds = m_bulkheadGeometry[0].Bounds;

                foreach (Geometry geom in m_bulkheadGeometry)
                {
                    Rect  bulkBounds = geom.Bounds;
                    Point topLeft    = new Point(0, 0);
                    topLeft.X = Math.Min(bulkBounds.Left, bounds.Left);
                    topLeft.Y = Math.Min(bulkBounds.Top, bounds.Top);

                    double right  = Math.Max(bulkBounds.Right, bounds.Right);
                    double bottom = Math.Max(bulkBounds.Bottom, bounds.Bottom);
                    Size   size   = new Size(right - topLeft.X, bottom - topLeft.Y);

                    bounds.Size     = size;
                    bounds.Location = topLeft;

                    double X = loc.X - bounds.Left;
                    double Y = loc.Y - bounds.Top;

                    Size3D hullSize = m_editableHull.GetSize();
                    double scale_X  = hullSize.X / bounds.Width;
                    double scale_Y  = hullSize.Y / bounds.Height;

                    X *= scale_X;
                    Y *= scale_Y;

                    switch (perspective)
                    {
                    case PerspectiveType.FRONT:
                        m_mouse_X = X - hullSize.X / 2;
                        m_mouse_Y = hullSize.Y - Y;
                        break;

                    case PerspectiveType.SIDE:
                        m_mouse_Y = hullSize.Y - Y;
                        m_mouse_Z = X;
                        break;

                    case PerspectiveType.TOP:
                        m_mouse_X = Y - hullSize.Y / 2;
                        m_mouse_Z = X;
                        break;
                    }
                }
            }

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (m_dragging)
                {
                    Rect   rect   = m_handles[m_draggingHandle].Rect;
                    double deltaX = (loc.X - m_lastDrag.X) / m_scale;
                    double deltaY = (loc.Y - m_lastDrag.Y) / m_scale;
                    rect.X += deltaX;
                    rect.Y += deltaY;

                    m_lastDrag = loc;

                    RectangleGeometry geom = new RectangleGeometry(rect);
                    geom.Transform = m_xform;

                    m_handles[m_draggingHandle] = geom;
                    InvalidateVisual();
                }
                else if (m_movingBulkhead && m_selectedBulkhead != NOT_SELECTED && m_editableHull.Bulkheads[m_selectedBulkhead].Type != Bulkhead.BulkheadType.BOW &&
                         (perspective == PerspectiveType.TOP || perspective == PerspectiveType.SIDE))
                {
                    double deltaX = (loc.X - m_lastDrag.X) / m_scale;
                    double deltaY = (loc.Y - m_lastDrag.Y) / m_scale;
                    m_lastDrag = loc;
                    m_editableHull.UpdateBulkheadPoint(m_selectedBulkhead, NOT_SELECTED, 0, 0, deltaX);

                    InvalidateVisual();
                }
            }
        }