예제 #1
0
        /// <summary>
        /// Executes the command.
        /// Adds a set of Line Elements. Opens a properties window and asks the user for two points or Joints for each one.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            try
            {
                Magnet p1 = services.GetPoint();
                services.TrackingService = VectorTrackingService.Instance;
                services.TrackingService.SetPoint(p1.SnapPositionInt);

                Magnet p2 = services.GetPoint();

                services.TrackingService = null;

                float  distance = (p2.SnapPosition - p1.SnapPosition).Length();
                string message  = string.Format("{0}: {1:G6} {2}", Culture.Get("Distance"), distance, services.Model.UnitSystem.UnitName(Canguro.Model.UnitSystem.Units.Distance));
                System.Windows.Forms.MessageBox.Show(message, Title);
            }
            catch (Canguro.Controller.CancelCommandException) { }
        }
예제 #2
0
        //public override void Run(Canguro.Controller.CommandServices services)
        //{
        //    List<Item> selection = GetSelection(services);
        //    if (selection.Count == 0)
        //        return;
        //    Stream stream = new MemoryStream();
        //    try
        //    {
        //        BinaryFormatter bformatter = new BinaryFormatter();
        //        Magnet magnet = services.GetPoint("selectPivot");
        //        bformatter.Serialize(stream, magnet.SnapPosition);
        //        bformatter.Serialize(stream, selection.Count);
        //        foreach (Item item in selection)
        //        {
        //            bformatter.Serialize(stream, item);
        //            item.IsSelected = true;
        //        }
        //        Clipboard.SetData("Canguro", stream);
        //    }
        //    finally
        //    {
        //        stream.Close();
        //    }
        //}

        /// <summary>
        /// Executes the command.
        /// Gets the selection and a pivot point, and adds them to the Clipboard with the key "Canguro"
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            Dictionary <uint, Joint> joints = new Dictionary <uint, Joint>();
            List <LineElement>       lines  = new List <LineElement>();
            List <AreaElement>       areas  = new List <AreaElement>();
            bool haveSelection = false;

            haveSelection = services.GetSelection(joints, lines, areas);
            if (!haveSelection)
            {
                services.GetMany(Culture.Get("selectItems"));
                haveSelection = services.GetSelection(joints, lines, areas);
            }
            if (haveSelection)
            {
                Magnet magnet = services.GetPoint(Culture.Get("selectPivot"));
                if (magnet != null)
                {
                    Microsoft.DirectX.Vector3 pivot = magnet.SnapPosition;
                    Clipboard.Clear();
                    object[] objs = new object[] { joints, lines, areas, pivot };

                    //// Test Serialization
                    //System.IO.MemoryStream s = new MemoryStream();
                    //new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter().Serialize(s, objs);

                    Clipboard.SetData("Canguro", objs);
                }
            }

            foreach (Item item in joints.Values)
            {
                if (item != null)
                {
                    item.IsSelected = true;
                }
            }
            foreach (Item item in lines)
            {
                if (item != null)
                {
                    item.IsSelected = true;
                }
            }
            foreach (Item item in areas)
            {
                if (item != null)
                {
                    item.IsSelected = true;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Executes the command.
        /// Moves the joint according to a given scale factor and pivot point.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            List <Canguro.Model.Joint> selection = new List <Canguro.Model.Joint>();
            List <Item> selectedItems            = services.GetSelection();

            if (selectedItems.Count == 0)
            {
                return;
            }

            foreach (Item item in selectedItems)
            {
                if (item is Joint)
                {
                    selection.Add((Joint)item);
                }
                else if (item is LineElement)
                {
                    LineElement l = (LineElement)item;
                    if (!selection.Contains(l.I))
                    {
                        selection.Add(l.I);
                    }
                    if (!selection.Contains(l.J))
                    {
                        selection.Add(l.J);
                    }
                }
            }

            Microsoft.DirectX.Vector3 piv;
            float scale = services.GetSingle(Culture.Get("getScale"));

            Controller.Snap.Magnet m = services.GetPoint(Culture.Get("pivotScalePoint"));
            if (m == null)
            {
                return;
            }
            piv = m.SnapPosition;

            foreach (Canguro.Model.Joint j in selection)
            {
                j.X = (j.X - piv.X) * scale + piv.X;
                j.Y = (j.Y - piv.Y) * scale + piv.Y;
                j.Z = (j.Z - piv.Z) * scale + piv.Z;
            }
        }
예제 #4
0
        /// <summary>
        /// Executes the command.
        /// Gets the parameters and calls beamGrid3D() to make the grid.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            if (section == null)
            {
                section = Canguro.Model.Section.SectionManager.Instance.DefaultFrameSection as Canguro.Model.Section.FrameSection;
            }
            services.GetProperties(Culture.Get("gridCmdTitle"), this);

            Controller.Snap.Magnet m = services.GetPoint(Culture.Get("selectGridOrigin"));
            if (m == null)
            {
                return;
            }
            Microsoft.DirectX.Vector3 o = m.SnapPosition;

            StraightFrameProps props = new StraightFrameProps();

            props.Section = section;
            beamGrid3D(services.Model, o.X, o.Y, o.Z, dx, 0, 0, 0, dy, 0, 0, 0, dz, nx + 1, ny + 1, nz + 1, true, props);
        }
예제 #5
0
        /// <summary>
        /// Executes the command.
        /// Gets the parameters and calls createCylinder to add a Cylinder to the model
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            if (section == null)
            {
                section = Canguro.Model.Section.SectionManager.Instance.DefaultFrameSection as Canguro.Model.Section.FrameSection;
            }
            services.GetProperties(Culture.Get("cylinderCmdTitle"), this);

            Controller.Snap.Magnet m = services.GetPoint(Culture.Get("selectCylinderCenter"));
            if (m == null)
            {
                return;
            }
            Microsoft.DirectX.Vector3 o = m.SnapPosition;

            StraightFrameProps props = new StraightFrameProps();

            props.Section = section;
            createCylinder(services.Model, o, r, c, h, s + 1, props);
        }
예제 #6
0
        //public override void Run(Canguro.Controller.CommandServices services)
        //{
        //    objectCount = 0;
        //    if (Clipboard.ContainsData("Canguro"))
        //    {
        //        Stream stream = (Stream)Clipboard.GetData("Canguro");
        //        Magnet magnet = services.GetPoint(Culture.Get("pasteCmdTitle"));

        //        BinaryFormatter bformatter = new BinaryFormatter();
        //        Microsoft.DirectX.Vector3 pivot = (Microsoft.DirectX.Vector3)bformatter.Deserialize(stream);
        //        Microsoft.DirectX.Vector3 v = magnet.SnapPosition - pivot;
        //        List<Joint> newJoints = new List<Joint>();
        //        List<LineElement> newLines = new List<LineElement>();
        //        ItemList<Joint> jList = services.Model.JointList;
        //        ItemList<LineElement> lList = services.Model.LineList;
        //        Dictionary<uint, Joint> jSelection = new Dictionary<uint, Joint>();
        //        Joint nJoint;
        //        LineElement nLine;

        //        objectCount = (int) bformatter.Deserialize(stream);
        //        for (int i = 0; i < objectCount; i++)
        //        {
        //            Element elem = (Element)bformatter.Deserialize(stream);

        //            if (elem is Joint)
        //            {
        //                Joint j = (Joint)elem;
        //                jList.Add(nJoint = new Joint(j.X + v.X, j.Y + v.Y, j.Z + v.Z));
        //                nJoint.Masses = j.Masses;
        //                nJoint.DoF = j.DoF;
        //                jSelection.Add(j.Id, nJoint);
        //                newJoints.Add(nJoint);
        //                CopyLoads(services.Model, j, nJoint);
        //            }
        //            if (elem is LineElement)
        //            {
        //                LineElement l = (LineElement)elem;
        //                lList.Add(nLine = new LineElement(l.Properties));
        //                nLine.I = jSelection[l.I.Id];
        //                nLine.J = jSelection[l.J.Id];
        //                nLine.Angle = l.Angle;
        //                newLines.Add(nLine);
        //                CopyLoads(services.Model, l, nLine);
        //            }
        //            JoinCmd.Join(services.Model, newJoints, newLines);
        //        }
        //    }
        //}

        /// <summary>
        /// Executes the command.
        /// Pastes the Items in the Clpboard under the key Canguro, in the current Model.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            objectCount = 0;
            if (Clipboard.ContainsData("Canguro"))
            {
                object[] data = (object[])Clipboard.GetData("Canguro");
                Dictionary <uint, Joint>  joints     = (Dictionary <uint, Joint>)data[0];
                Dictionary <uint, Joint>  jSelection = new Dictionary <uint, Joint>();
                IList <LineElement>       lines      = (IList <LineElement>)data[1];
                IList <AreaElement>       areas      = (IList <AreaElement>)data[2];
                Microsoft.DirectX.Vector3 pivot      = (Microsoft.DirectX.Vector3)data[3];

                ItemList <Joint>       jList = services.Model.JointList;
                ItemList <LineElement> lList = services.Model.LineList;
                ItemList <AreaElement> aList = services.Model.AreaList;

                Joint       nJoint;
                LineElement nLine;
                AreaElement nArea;
                Magnet      magnet = services.GetPoint(Culture.Get("pasteCmdTitle"));
                if (magnet == null)
                {
                    objectCount = 0;
                }
                else
                {
                    objectCount = joints.Count + lines.Count;
                    Microsoft.DirectX.Vector3 v  = magnet.SnapPosition - pivot;
                    List <Joint>       newJoints = new List <Joint>();
                    List <LineElement> newLines  = new List <LineElement>();
                    List <AreaElement> newAreas  = new List <AreaElement>();

                    Dictionary <string, Layer> layers = new Dictionary <string, Layer>();
                    foreach (Layer l in services.Model.Layers)
                    {
                        if (l != null)
                        {
                            layers.Add(l.Name, l);
                        }
                    }


                    foreach (uint jid in joints.Keys)
                    {
                        Joint j = (joints[jid] == null) ? jList[jid] : joints[jid];
                        jList.Add(nJoint = new Joint(j.X + v.X, j.Y + v.Y, j.Z + v.Z));
                        nJoint.Masses    = j.Masses;
                        if (!layers.ContainsKey(j.Layer.Name))
                        {
                            Layer lay = new Layer(j.Layer.Name);
                            services.Model.Layers.Add(lay);
                            layers.Add(lay.Name, lay);
                        }
                        nJoint.Layer = layers[j.Layer.Name];
                        nJoint.DoF   = j.DoF;
                        jSelection.Add(jid, nJoint);
                        newJoints.Add(nJoint);
                        CopyLoads(services.Model, j, nJoint);
                    }
                    foreach (LineElement l in lines)
                    {
                        if (!layers.ContainsKey(l.Layer.Name))
                        {
                            Layer lay = new Layer(l.Layer.Name);
                            services.Model.Layers.Add(lay);
                            layers.Add(lay.Name, lay);
                        }
                        lList.Add(nLine = new LineElement(l, jSelection[l.I.Id], jSelection[l.J.Id]));
                        nLine.Layer     = layers[l.Layer.Name];
                        newLines.Add(nLine);
                        CopyLoads(services.Model, l, nLine);
                    }
                    foreach (AreaElement a in areas)
                    {
                        if (!layers.ContainsKey(a.Layer.Name))
                        {
                            Layer lay = new Layer(a.Layer.Name);
                            services.Model.Layers.Add(lay);
                            layers.Add(lay.Name, lay);
                        }

                        aList.Add(nArea = new AreaElement(a, jSelection[a.J1.Id], jSelection[a.J2.Id], jSelection[a.J3.Id], (a.J4 != null) ? jSelection[a.J4.Id] : null));
                        if (a.J4 != null)
                        {
                            nArea.J4 = jSelection[a.J4.Id];
                        }
                        nArea.Layer = layers[a.Layer.Name];
                        newAreas.Add(nArea);
                        CopyLoads(services.Model, a, nArea);
                    }
                    JoinCmd.Join(services.Model, newJoints, newLines, newAreas);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Executes the command.
        /// Copies the selected Items in a series around a given rotation axis.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            Dictionary <Joint, Joint> joints     = new Dictionary <Joint, Joint>();
            Dictionary <Joint, Joint> jSelection = new Dictionary <Joint, Joint>();
            List <LineElement>        lines      = new List <LineElement>();
            List <LineElement>        lSelection = new List <LineElement>();
            List <AreaElement>        areas      = new List <AreaElement>();
            List <AreaElement>        aSelection = new List <AreaElement>();
            ItemList <Joint>          jList      = services.Model.JointList;
            ItemList <LineElement>    lList      = services.Model.LineList;
            ItemList <AreaElement>    aList      = services.Model.AreaList;
            Joint       nJoint;
            LineElement nLine;
            AreaElement nArea;

            List <Item> selection = services.GetSelection();

            if (selection.Count == 0)
            {
                return;
            }

            foreach (Item item in selection)
            {
                if (item is Joint)
                {
                    jSelection.Add((Joint)item, null);
                    joints.Add((Joint)item, null);
                }
                else if (item is LineElement)
                {
                    LineElement l = (LineElement)item;
                    lSelection.Add(l);
                    lines.Add(l);
                    if (!jSelection.ContainsKey(l.I))
                    {
                        jSelection.Add(l.I, null);
                        joints.Add(l.I, null);
                    }
                    if (!jSelection.ContainsKey(l.J))
                    {
                        jSelection.Add(l.J, null);
                        joints.Add(l.J, null);
                    }
                }
                else if (item is AreaElement)
                {
                    AreaElement a = (AreaElement)item;
                    aSelection.Add(a);
                    areas.Add(a);
                    if (!jSelection.ContainsKey(a.J1))
                    {
                        jSelection.Add(a.J1, null);
                        joints.Add(a.J1, null);
                    }
                    if (!jSelection.ContainsKey(a.J2))
                    {
                        jSelection.Add(a.J2, null);
                        joints.Add(a.J2, null);
                    }
                    if (!jSelection.ContainsKey(a.J3))
                    {
                        jSelection.Add(a.J3, null);
                        joints.Add(a.J3, null);
                    }
                    if (a.J4 != null && !jSelection.ContainsKey(a.J4))
                    {
                        jSelection.Add(a.J4, null);
                        joints.Add(a.J4, null);
                    }
                }
            }

            Microsoft.DirectX.Vector3 v, v2;
            uint n = (uint)services.GetSingle(Culture.Get("getArrayRepetition"));

            float dAngle = float.Parse(services.GetString(Culture.Get("getPolarArrayAngle")));

            dAngle *= (float)Math.PI / 180.0F;
            float angle = 0.0F;

            Controller.Snap.Magnet m = services.GetPoint(Culture.Get("getPolarRotationCenter"));
            if (m == null)
            {
                return;
            }
            v = m.SnapPosition;

            services.TrackingService = LineTrackingService.Instance;
            services.TrackingService.SetPoint(m.SnapPositionInt);

            m = services.GetPoint(Culture.Get("getPolarRotationCenter"));
            if (m == null)
            {
                return;
            }
            v2 = m.SnapPosition;
            if (v2.Equals(v))
            {
                Canguro.View.GraphicView view = Canguro.View.GraphicViewManager.Instance.ActiveView;
                Vector3 v1Tmp = new Vector3(0, 0, 0);
                Vector3 v2Tmp = new Vector3(0, 0, 1);
                view.Unproject(ref v1Tmp);
                view.Unproject(ref v2Tmp);
                v2 = v2 + v1Tmp - v2Tmp;
            }
            services.TrackingService = null;

            List <Joint>       newJoints = new List <Joint>();
            List <LineElement> newLines  = new List <LineElement>();
            List <AreaElement> newAreas  = new List <AreaElement>();


            for (int i = 1; i <= n; i++)
            {
                angle += dAngle;

                Matrix trans1 = new Matrix();
                trans1.Translate(-v);
                Matrix rot = new Matrix();
                rot.RotateAxis(v2 - v, angle);
                Matrix trans2 = new Matrix();
                trans2.Translate(v);
                rot = trans1 * rot * trans2;

                foreach (Joint j in joints.Keys)
                {
                    Vector3 pos = new Vector3(j.X, j.Y, j.Z);
                    pos.TransformCoordinate(rot);

                    jList.Add(nJoint = new Joint(pos.X, pos.Y, pos.Z));
                    nJoint.Masses    = j.Masses;
                    nJoint.DoF       = j.DoF;
                    jSelection[j]    = nJoint;
                    newJoints.Add(nJoint);
                }
                foreach (LineElement l in lines)
                {
                    lList.Add(nLine = new LineElement(l, jSelection[l.I], jSelection[l.J]));
                    newLines.Add(nLine);
                }
                foreach (AreaElement a in areas)
                {
                    aList.Add(nArea = new AreaElement(a, jSelection[a.J1], jSelection[a.J2], jSelection[a.J3], (a.J4 != null) ? jSelection[a.J4] : null));
                    newAreas.Add(nArea);
                }
            }
            JoinCmd.Join(services.Model, newJoints, newLines, newAreas);
        }
예제 #8
0
        /// <summary>
        /// Executes the command.
        /// Moves the selected Item's Joints around a given point and with a given angle.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            Dictionary <Joint, Joint> joints = new Dictionary <Joint, Joint>();
            ItemList <Joint>          jList  = services.Model.JointList;
            ItemList <LineElement>    lList  = services.Model.LineList;

            List <Item> selection = services.GetSelection();

            if (selection.Count == 0)
            {
                return;
            }

            foreach (Item item in selection)
            {
                if (item is Joint)
                {
                    joints.Add((Joint)item, null);
                }
                else if (item is LineElement)
                {
                    LineElement l = (LineElement)item;
                    if (!joints.ContainsKey(l.I))
                    {
                        joints.Add(l.I, null);
                    }
                    if (!joints.ContainsKey(l.J))
                    {
                        joints.Add(l.J, null);
                    }
                }
            }

            Microsoft.DirectX.Vector3 v, v2;

            float angle = float.Parse(services.GetString(Culture.Get("getRotationAngle")));

            angle *= (float)Math.PI / 180.0F;
            Controller.Snap.Magnet m = services.GetPoint(Culture.Get("getRotationCenter"));
            if (m == null)
            {
                return;
            }

            v = m.SnapPosition;

            services.TrackingService = LineTrackingService.Instance;
            services.TrackingService.SetPoint(m.SnapPositionInt);

            m = services.GetPoint(Culture.Get("getPolarRotationCenter"));
            if (m == null)
            {
                return;
            }
            v2 = m.SnapPosition;
            if (v2.Equals(v))
            {
                Canguro.View.GraphicView view = Canguro.View.GraphicViewManager.Instance.ActiveView;
                Vector3 v1Tmp = new Vector3(0, 0, 0);
                Vector3 v2Tmp = new Vector3(0, 0, 1);
                view.Unproject(ref v1Tmp);
                view.Unproject(ref v2Tmp);
                v2 = v2 + v1Tmp - v2Tmp;
            }
            services.TrackingService = null;

            Matrix trans1 = new Matrix();

            trans1.Translate(-v);
            Matrix rot = new Matrix();

            rot.RotateAxis(v2 - v, angle);
            Matrix trans2 = new Matrix();

            trans2.Translate(v);

            rot = trans1 * rot * trans2;

            foreach (Joint j in joints.Keys)
            {
                Vector3 pos = new Vector3(j.X, j.Y, j.Z);

                pos.TransformCoordinate(rot);

                j.X = pos.X;
                j.Y = pos.Y;
                j.Z = pos.Z;
            }
        }
예제 #9
0
        /// <summary>
        /// Executes the command.
        /// Makes a copy of the selected items with inverted positions with respect to a mirror plane, defined by 3 points.
        /// If the points are colinear, the 3rd point is taken to be perpendicular to the view.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            Dictionary <uint, Joint> joints = new Dictionary <uint, Joint>();
            List <LineElement>       lines  = new List <LineElement>();
            List <AreaElement>       areas  = new List <AreaElement>();

            services.GetSelection(joints, lines, areas);

            Dictionary <uint, Joint> jSelection = new Dictionary <uint, Joint>();

            Microsoft.DirectX.Vector3[] pivots = new Microsoft.DirectX.Vector3[3];

            // Get 3 Points
            Magnet m = services.GetPoint(Culture.Get("selectPlainPoints"));

            pivots[0] = m.SnapPosition;

            m         = services.GetPoint(Culture.Get("selectPlainPoints"));
            pivots[1] = m.SnapPosition;

            m         = services.GetPoint(Culture.Get("selectPlainPoints"));
            pivots[2] = m.SnapPosition;
            Vector3 v1 = pivots[0] - pivots[1];
            Vector3 v2 = pivots[1] - pivots[2];

            if (Vector3.Cross(v1, v2).LengthSq() < 0.0001)     // If Colinear, take perpendicular to the active view.
            {
                Canguro.View.GraphicView view = Canguro.View.GraphicViewManager.Instance.ActiveView;
                v1 = new Vector3(0, 0, 0);
                v2 = new Vector3(0, 0, 1);
                view.Unproject(ref v1);
                view.Unproject(ref v2);
                pivots[2] = pivots[2] + v1 - v2;
            }

            ItemList <Joint>       jList = services.Model.JointList;
            ItemList <LineElement> lList = services.Model.LineList;
            ItemList <AreaElement> aList = services.Model.AreaList;

            Joint              nJoint;
            LineElement        nLine;
            AreaElement        nArea;
            List <Joint>       newJoints = new List <Joint>();
            List <LineElement> newLines  = new List <LineElement>();
            List <AreaElement> newAreas  = new List <AreaElement>();

            foreach (uint jid in joints.Keys)
            {
                Joint   j          = jList[jid];
                Vector3 currentPos = new Vector3(j.X, j.Y, j.Z);
                Vector3 newPos     = Mirror(currentPos, pivots);
                jList.Add(nJoint = new Joint(newPos.X, newPos.Y, newPos.Z));
                nJoint.Masses    = j.Masses;
                nJoint.DoF       = j.DoF;
                jSelection.Add(jid, nJoint);
                newJoints.Add(nJoint);
            }
            foreach (LineElement l in lines)
            {
                lList.Add(nLine = new LineElement(l, jSelection[l.I.Id], jSelection[l.J.Id]));
                newLines.Add(nLine);
            }
            foreach (AreaElement a in areas)
            {
                aList.Add(nArea = new AreaElement(a, jSelection[a.J1.Id], jSelection[a.J2.Id], jSelection[a.J3.Id], (a.J4 != null) ? jSelection[a.J4.Id] : null));
                newAreas.Add(nArea);
            }
            JoinCmd.Join(services.Model, newJoints, newLines, newAreas);
        }