示例#1
0
        /// <summary>
        /// Executes the command. 
        /// Creates a series of connected Line Elements given at least 2 points. Each subsequent point given adds a new Line Element.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            LineElement line;
            Joint joint1, joint2;
            LineProps props = new StraightFrameProps();
            List<LineElement> newLines = new List<LineElement>();
            List<AreaElement> newAreas = new List<AreaElement>();

            services.GetProperties(Culture.Get("addLineProps"), props);

            joint1 = services.GetJoint(newLines);
            services.TrackingService = LineTrackingService.Instance;
            services.TrackingService.SetPoint(joint1.Position);

            try
            {
                while ((joint2 = services.GetJoint(newLines)) != null)
                {
                    if (joint2 != joint1)
                    {
                        services.Model.LineList.Add(line = new LineElement(props, joint1, joint2));
                        newLines.Add(line);
                        joint1 = joint2;
                        services.TrackingService.SetPoint(joint1.Position);
                        // Para que se refleje el cambio inmediatamente
                        services.Model.ChangeModel();
                    }
                }
            }
            catch (Canguro.Controller.CancelCommandException) { }
            if (newLines.Count == 0)
                services.Model.Undo.Rollback();
            else
                JoinCmd.Join(services.Model, new List<Joint>(), newLines, newAreas);
        }
示例#2
0
        public override object Clone()
        {
            StraightFrameProps clone = (StraightFrameProps)base.Clone();

            if (clone.section != null)
            {
                if (Model.Instance.Sections[clone.section.Name] == null)
                {
                    Model.Instance.Sections[clone.section.Name] = clone.section;
                }
                else if (Model.Instance.Sections[clone.section.Name] is Canguro.Model.Section.FrameSection)
                {
                    clone.section = (Canguro.Model.Section.FrameSection)Model.Instance.Sections[clone.section.Name];
                }
            }
            return(clone);
        }
        /// <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);
        }
        /// <summary>
        /// Creates a cylinder and adds it to the model.
        /// </summary>
        /// <param name="model">The Model object</param>
        /// <param name="C">The Center of the base</param>
        /// <param name="radius">The radius</param>
        /// <param name="cols">Number of columns</param>
        /// <param name="height">Height of each story</param>
        /// <param name="stories">Number of stories</param>
        /// <param name="props">Frame properties to use in all elements</param>
        protected void createCylinder(Canguro.Model.Model model, Vector3 C, float radius, int cols, float height, int stories, StraightFrameProps props)
        {
            float[,] columns = new float[cols, 3];
            int i, f, c;
            Queue<Joint> jQueue = new Queue<Joint>();
            Joint joint, first, prev;
            joint = prev = first = null;
            LineElement line;

            double angle, delta = 2 * Math.PI / (double)cols;
            float[] angles = new float[cols];

            for (i = 0, angle = 0; i < cols; angle += delta, i++)
            {
                columns[i, 0] = (float)(C.X + Math.Cos(angle) * radius);
                columns[i, 1] = (float)(C.Y + Math.Sin(angle) * radius);
                columns[i, 2] = (float)C.Z;
                angles[i] = (float)(angle * 180.0 / Math.PI);
            }

            JointDOF baseDoF = new JointDOF();
            baseDoF.T1 = baseDoF.T2 = baseDoF.T3 = JointDOF.DofType.Restrained;
            for (f = 0; f < stories; f++)
            {
                for (c = 0; c < cols; c++)
                {
                    joint = new Joint(columns[c, 0], columns[c, 1], columns[c, 2] + height * f);
                    if (c == 0) first = joint;
                    if (f == 0) joint.DoF = baseDoF;
                    model.JointList.Add(joint);
                    jQueue.Enqueue(joint);
                    if (f > 0)
                    {
                        model.LineList.Add(line = new LineElement(props));
                        line.I = jQueue.Dequeue();
                        line.J = joint;
                        line.Angle = angles[c];
                        if (c > 0)
                        {
                            model.LineList.Add(line = new LineElement(props));
                            line.I = prev;
                            line.J = joint;
                            if (c == cols - 1)
                            {
                                model.LineList.Add(line = new LineElement(props));
                                line.I = joint;
                                line.J = first;
                            }
                        }
                        prev = joint;
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Reads a DXF file and adds all the lines defined in it to the given Model
        /// </summary>
        /// <param name="path">The path to the DXF file</param>
        /// <param name="model">The current Model object</param>
        public static void Import(string path, Canguro.Model.Model model)
        {
            if (path.Length > 0)
            {
                string[] file = File.ReadAllLines(path);
                List<string> search = new List<string>(new string[] { "LINE", "10", "20", "30", "11", "21", "31", "LWPOLYLINE" });
                int state = 0;
                Joint ji = null;
                Joint jj = null;
                StraightFrameProps props = new StraightFrameProps();
                List<LineElement> newLines = new List<LineElement>();
                List<AreaElement> newAreas = new List<AreaElement>();
                List<Joint> newJoints = new List<Joint>();

                bool addLine = false;
                bool polyline = false;
                for (int i = 0; i < file.Length; i++)
                {
                    string line = file[i].Trim().ToUpper();
                    while (!search.Contains(line) && i < file.Length - 1)
                        line = file[++i].Trim().ToUpper();
                    state = search.IndexOf(line);
                    if (state == 0 || state > 6)
                    {
                        addLine = true;
                        jj = null;
                        ji = null;
                    }
                    if (state == 7)
                        polyline = true;

                    if (!addLine)
                        continue;
                    if (i == file.Length - 1)
                        break;
                    line = file[++i].Trim();
                    switch (state)
                    {
                        case 1:
                            jj = (polyline) ? ji : jj;
                            ji = new Joint(Convert.ToSingle(line), 0, 0);
                            if (polyline && jj != null)
                                AddLine(model, ji, jj, props, newJoints, newLines);
                            break;
                        case 2:
                            if (ji != null)
                                ji.Y = Convert.ToSingle(line);
                            break;
                        case 3:
                            if (ji != null)
                                ji.Z = Convert.ToSingle(line);
                            break;
                        case 4:
                            jj = new Joint(Convert.ToSingle(line), 0, 0);
                            break;
                        case 5:
                            if (addLine && jj != null)
                                jj.Y = Convert.ToSingle(line);
                            AddLine(model, ji, jj, props, newJoints, newLines);
                            polyline = false;
                            break;
                        case 6:
                            if (jj != null)
                                jj.Z = Convert.ToSingle(line);
                            break;
                    }
                }
                JoinCmd.Join(model, newJoints, newLines, newAreas);
            }
        }
示例#6
0
 /// <summary>
 /// Adds a Line Element to the given Model
 /// </summary>
 /// <param name="model">The Model object</param>
 /// <param name="ji">The initial Joint</param>
 /// <param name="jj">The final Joint</param>
 /// <param name="props">Frame properties for the Line Element</param>
 /// <param name="newJoints">List of new Joints to use in Join</param>
 /// <param name="newLines">List of new Line Elements to use in Join</param>
 private static void AddLine(Canguro.Model.Model model, Joint ji, Joint jj, StraightFrameProps props, List<Joint> newJoints, List<LineElement> newLines)
 {
     if (ji != null && jj != null)
     {
         model.JointList.Add(ji);
         model.JointList.Add(jj);
         LineElement elem = new LineElement(props, ji, jj);
         newJoints.Add(ji);
         newJoints.Add(jj);
         newLines.Add(elem);
         model.LineList.Add(elem);
     }
 }
示例#7
0
        /// <summary>
        /// Creates a Grid with frames given an origin, 3 vectors and number of bays in the 3 directions.
        /// Joints at the base are not connected and have restricted translation.
        /// </summary>
        /// <param name="model">The Model object to add the Grid to.</param>
        /// <param name="x0">X Component of the Origin point</param>
        /// <param name="y0">Y Component of the Origin point</param>
        /// <param name="z0">Z Component of the Origin point</param>
        /// <param name="ux">X Component of the U directional vector</param>
        /// <param name="uy">Y Component of the U directional vector</param>
        /// <param name="uz">Z Component of the U directional vector</param>
        /// <param name="vx">X Component of the V directional vector</param>
        /// <param name="vy">Y Component of the V directional vector</param>
        /// <param name="vz">Z Component of the V directional vector</param>
        /// <param name="wx">X Component of the W directional vector</param>
        /// <param name="wy">Y Component of the W directional vector</param>
        /// <param name="wz">Z Component of the W directional vector</param>
        /// <param name="nu">Number of bays in the U direction</param>
        /// <param name="nv">Number of bays in the V direction</param>
        /// <param name="nw">Number of bays in the W direction</param>
        /// <param name="doLines">If set to false, only the Joints are created</param>
        /// <param name="props">Frame properties to use in all the Line Elements created</param>
        private static void beamGrid3D(Canguro.Model.Model model, float x0, float y0, float z0, float ux, float uy, float uz,
            float vx, float vy, float vz, float wx, float wy, float wz, int nu, int nv, int nw, bool doLines, StraightFrameProps props)
        {
            Joint joint;
            Joint[] joints = new Joint[nu * nv * nw];
            Stack<Joint> jStack = new Stack<Joint>();
            JointDOF baseDoF = new JointDOF();
            baseDoF.T1 = baseDoF.T2 = baseDoF.T3 = JointDOF.DofType.Restrained;

            for (int i = 0; i < nw; i++)
                for (int j = 0; j < nv; j++)
                    for (int k = 0; k < nu; k++)
                    {
                        model.JointList.Add(joints[i * nu * nv + j * nu + k] =
                            joint = new Joint(x0 + k * ux + j * vx + i * wx,
                                                    y0 + j * uy + j * vy + i * wy,
                                                    z0 + i * uz + i * vz + i * wz));
                        if (i == 0)
                            joints[i * nu * nv + j * nu + k].DoF = baseDoF;
                    }

            if (doLines)
            {
                LineElement beam;
                for (int i = 0; i < nw; i++)
                    for (int j = 0; j < nv; j++)
                        for (int k = 0; k < nu; k++)
                        {
                            jStack.Push(joints[i * nu * nv + j * nu + k]);
                            if (i > 0)
                            {
                                jStack.Push(joints[(i - 1) * nu * nv + j * nu + k]);
                                model.LineList.Add(beam = new LineElement(props));
                                beam.I = jStack.Pop();
                                beam.J = jStack.Peek();
                                if (j > 0)
                                {
                                    jStack.Push(joints[i * nu * nv + (j - 1) * nu + k]);
                                    model.LineList.Add(beam = new LineElement(props));
                                    beam.I = jStack.Pop();
                                    beam.J = jStack.Peek();
                                }
                                if (k > 0)
                                {
                                    jStack.Push(joints[i * nu * nv + j * nu + k - 1]);
                                    model.LineList.Add(beam = new Canguro.Model.LineElement(props));
                                    beam.I = jStack.Pop();
                                    beam.J = jStack.Peek();
                                }
                            }
                            jStack.Pop();
                        }
            }
        }
示例#8
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);
        }
        private void MakeArc(Canguro.Model.Model model, Vector3 C, Vector3 N, Joint from, Joint until, Joint passing, int segments)
        {
            Vector3 p0 = from.Position;
            Vector3 p1 = until.Position;
            Vector3 p2 = passing.Position;
            Vector3 a = Vector3.Normalize(C - p0);
            Vector3 b = Vector3.Normalize(C - p1);
            Vector3 c = Vector3.Normalize(C - p2);
            N.Normalize();
            float ang = (float)Math.Acos(Vector3.Dot(a, b));
            float p2Ang = (float)Math.Acos(Vector3.Dot(a, c));

            ang = (Vector3.Dot(Vector3.Cross(a, N), b) > 0) ? 2f * (float)Math.PI-ang : ang;
            p2Ang = (Vector3.Dot(Vector3.Cross(a, N), c) > 0) ? 2f * (float)Math.PI - p2Ang : p2Ang;

            List<Joint> joints = new List<Joint>();
            joints.Add(from);
            float angle = 0;
            ang /= segments;

            for (int i = 0; i < segments - 1; i++)
            {
                angle += ang;

                Matrix trans1 = new Matrix();
                trans1.Translate(-C);
                Matrix rot = new Matrix();
                rot.RotateAxis(N, angle);
                Matrix trans2 = new Matrix();
                trans2.Translate(C);
                rot = trans1 * rot * trans2;
                Vector3 pos = from.Position;
                pos.TransformCoordinate(rot);
                if (Math.Abs(angle) > Math.Abs(p2Ang) && Math.Abs(angle) < Math.Abs(p2Ang + ang))
                    joints.Add(passing);
                Joint joint = new Joint(pos.X, pos.Y, pos.Z);
                joints.Add(joint);
                model.JointList.Add(joint);
            }
            joints.Add(until);
            StraightFrameProps props = new StraightFrameProps();
            for (int i = 1; i < joints.Count; i++)
            {
                model.LineList.Add(new LineElement(props, joints[i - 1], joints[i]));
            }
        }