Esempio n. 1
0
        public void PcShouldNotAdvance()
        {
            var clock = new Mock <IClock>();

            clock.Setup(x => x.AddConnectedComponent(It.IsAny <IClockConnectedComponent>()));

            var bus         = new Mock <IBus>();
            var controlUnit = new Mock <IControlUnit>();

            ControlLine countEnableLine = new ControlLine(ControlLineId.PC_ENABLE);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.PC_ENABLE)).Returns(countEnableLine);

            ControlLine busOutputLine = new ControlLine(ControlLineId.PC_OUT);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.PC_OUT)).Returns(busOutputLine);

            ControlLine busInputLine = new ControlLine(ControlLineId.PC_IN);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.PC_IN)).Returns(busInputLine);

            var pc = new ProgramCounter(clock.Object, bus.Object, controlUnit.Object);

            byte v1 = pc.Value;

            pc.OnRisingEdge();
            byte v2 = pc.Value;

            Assert.Equal(v1, v2);
        }
Esempio n. 2
0
        public void ValueShouldCarry(int aValue, int bValue, bool sub)
        {
            var bus         = new Mock <IBus>();
            var controlUnit = new Mock <IControlUnit>();
            var aReg        = new Mock <IRegister>();
            var bReg        = new Mock <IRegister>();

            aReg.SetupGet(x => x.Value).Returns((byte)aValue);
            bReg.SetupGet(x => x.Value).Returns((byte)bValue);

            ControlLine subtractLine  = new ControlLine(ControlLineId.SUBTRACT);
            ControlLine busOutputLine = new ControlLine(ControlLineId.SUM_OUT);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.SUBTRACT)).Returns(subtractLine);
            controlUnit.Setup(x => x.GetControlLine(ControlLineId.SUM_OUT)).Returns(busOutputLine);

            // Are we adding or subtracting?
            subtractLine.State = sub;

            var alu = new Alu(bus.Object, controlUnit.Object, aReg.Object, bReg.Object);

            // Carry will return the carried value not the intended value
            if (sub)
            {
                Assert.NotEqual(aValue - bValue, alu.Value);
            }
            else
            {
                Assert.NotEqual(aValue + bValue, alu.Value);
            }


            Assert.True(alu.Carry);
        }
Esempio n. 3
0
        private bool passCompileControlFlow(List <StringTokenized> lines)
        {
            foreach (ControlLine cl in m_ControlLines)
            {
                if (cl.Line.Tokens[0].Value == ".else")
                {
                    lines[cl.LineIndex].CompiledString = "; .else";
                    string compiled = "_L" + cl.LineIndex + ":" + "; } ";
                    lines[cl.BracketPair.LineEnd].CompiledString = compiled;
                }
                else if ((cl.Line.Tokens[0].Value == ".if") || (cl.Line.Tokens[0].Value == ".elseif"))
                {
                    string assembled = assembleControlLine(cl);
                    if (assembled == null)
                    {
                        return(false);
                    }
                    lines[cl.LineIndex].CompiledString = assembled;
                    assembled = string.Empty;
                    if (cl.HasNextControlLine)
                    {
                        ControlLine cl2 = cl.NextControlLine;
                        while (cl2.HasNextControlLine)
                        {
                            cl2 = cl2.NextControlLine;
                        }
                        assembled  = "jmp _L" + cl2.LineIndex + "; } " + "\n";
                        assembled += "_L" + cl.LineIndex + ":";
                    }
                    else
                    {
                        assembled = "_L" + cl.LineIndex + ":" + "; }";
                    }
                    lines[cl.BracketPair.LineEnd].CompiledString = assembled;
                }
                else if (cl.Line.Tokens[0].Value == ".while")
                {
                    string assembled = string.Format("_LW{0}:\n", cl.LineIndex) + assembleControlLine(cl);
                    if (assembled == null)
                    {
                        return(false);
                    }
                    lines[cl.LineIndex].CompiledString           = assembled;
                    lines[cl.BracketPair.LineEnd].CompiledString = string.Format("jmp _LW{0}\n_L{0}:", cl.LineIndex) + "; }";
                }
            }

            foreach (BracketPair bp in m_Brackets)
            {
                if (lines[bp.LineBegin].CompiledString == null)
                {
                    lines[bp.LineBegin].CompiledString = "; {";
                }
                if (lines[bp.LineEnd].CompiledString == null)
                {
                    lines[bp.LineEnd].CompiledString = "; }";
                }
            }
            return(true);
        }
Esempio n. 4
0
        public void RamReadValueFromBus()
        {
            byte address       = 0x04;
            byte expectedValue = 0x55;

            var bus         = new Mock <IBus>();
            var controlUnit = new Mock <IControlUnit>();
            var marReg      = new Mock <IRegister>();

            bus.SetupGet(x => x.Value).Returns(expectedValue);

            marReg.SetupGet(x => x.Value).Returns(address);

            ControlLine busInputLine  = new ControlLine(ControlLineId.RAM_IN);
            ControlLine busOutputLine = new ControlLine(ControlLineId.RAM_OUT);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.RAM_IN)).Returns(busInputLine);
            controlUnit.Setup(x => x.GetControlLine(ControlLineId.RAM_OUT)).Returns(busOutputLine);

            var ram = new Ram(bus.Object, controlUnit.Object, marReg.Object);

            // Read from the bus
            busInputLine.State = true;
            busInputLine.onTransition();

            byte read = ram.Read();

            Assert.Equal(expectedValue, read);
        }
Esempio n. 5
0
        public void Arithmetic(byte aValue, byte bValue, bool sub)
        {
            var bus         = new Mock <IBus>();
            var controlUnit = new Mock <IControlUnit>();
            var aReg        = new Mock <IRegister>();
            var bReg        = new Mock <IRegister>();

            aReg.SetupGet(x => x.Value).Returns(aValue);
            bReg.SetupGet(x => x.Value).Returns(bValue);

            ControlLine subtractLine  = new ControlLine(ControlLineId.SUBTRACT);
            ControlLine busOutputLine = new ControlLine(ControlLineId.SUM_OUT);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.SUBTRACT)).Returns(subtractLine);
            controlUnit.Setup(x => x.GetControlLine(ControlLineId.SUM_OUT)).Returns(busOutputLine);

            // Are we adding or subtracting?
            subtractLine.State = sub;

            var alu = new Alu(bus.Object, controlUnit.Object, aReg.Object, bReg.Object);

            if (sub)
            {
                Assert.Equal(aValue - bValue, alu.Value);
            }
            else
            {
                Assert.Equal(aValue + bValue, alu.Value);
            }

            Assert.False(alu.Zero);
            Assert.False(alu.Carry);
        }
Esempio n. 6
0
        public void ReadWriteRamByte()
        {
            byte address = 0x04;
            byte value   = 0x77;

            var bus         = new Mock <IBus>();
            var controlUnit = new Mock <IControlUnit>();
            var marReg      = new Mock <IRegister>();

            marReg.SetupGet(x => x.Value).Returns(address);

            ControlLine busInputLine  = new ControlLine(ControlLineId.RAM_IN);
            ControlLine busOutputLine = new ControlLine(ControlLineId.RAM_OUT);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.RAM_IN)).Returns(busInputLine);
            controlUnit.Setup(x => x.GetControlLine(ControlLineId.RAM_OUT)).Returns(busOutputLine);

            var ram = new Ram(bus.Object, controlUnit.Object, marReg.Object);

            // Write and then read a byte from RAM, check they are consistent
            ram.Write(value);
            byte read = ram.Read();

            Assert.Equal(read, value);
        }
Esempio n. 7
0
        public void PcReadFromBus()
        {
            byte expectedValue = 0xF0;

            var clock = new Mock <IClock>();

            clock.Setup(x => x.AddConnectedComponent(It.IsAny <IClockConnectedComponent>()));

            var bus = new Mock <IBus>();

            bus.SetupGet(x => x.Value).Returns(expectedValue);

            var controlUnit = new Mock <IControlUnit>();

            ControlLine countEnableLine = new ControlLine(ControlLineId.PC_ENABLE);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.PC_ENABLE)).Returns(countEnableLine);

            ControlLine busOutputLine = new ControlLine(ControlLineId.PC_OUT);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.PC_OUT)).Returns(busOutputLine);

            ControlLine busInputLine = new ControlLine(ControlLineId.PC_IN);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.PC_IN)).Returns(busInputLine);

            busInputLine.State = true;

            var pc = new ProgramCounter(clock.Object, bus.Object, controlUnit.Object);

            pc.OnRisingEdge();

            Assert.Equal(expectedValue, pc.Value);
        }
Esempio n. 8
0
        private string assembleControlLine(ControlLine cl)
        {
            string assembled = string.Empty;

            if (cl.Line.Tokens[1].TokenType == TokenType.Register)
            {
                switch (cl.Line.Tokens[1].Value.Trim())
                {
                case "a":
                    assembled += "cmp " + cl.Line.Tokens[3].Value + "; " + cl.Line.Line.Replace("\t", string.Empty) + "\n";
                    break;

                case "x":
                    assembled += "cpx " + cl.Line.Tokens[3].Value + " ; " + cl.Line.Line.Replace("\t", string.Empty) + "\n";
                    break;

                case "y":
                    assembled += "cpy " + cl.Line.Tokens[3].Value + "; " + cl.Line.Line.Replace("\t", string.Empty) + "\n";
                    break;

                default:
                    iLine = cl.LineIndex;
                    return(null);
                }
            }
            else if (cl.Line.Tokens[1].TokenType == TokenType.Variable)
            {
                assembled += "lda " + cl.Line.Tokens[1].Value + "; " + cl.Line.Line.Replace("\t", string.Empty) + "\ncmp " + cl.Line.Tokens[3].Value + "\n";
            }
            switch (cl.Line.Tokens[2].Value.Trim())
            {
            case "<":
                assembled += "bcs _L" + cl.LineIndex;
                break;

            case ">":
                assembled += "bcc _L" + cl.LineIndex + "\n";
                assembled += "beq _L" + cl.LineIndex;
                break;

            case "<=":
                assembled += "bcs _L" + cl.LineIndex + "\n";
                assembled += "bne _L" + cl.LineIndex;
                break;

            case ">=":
                assembled += "bcc _L" + cl.LineIndex;
                break;

            case "==":
                assembled += "bne _L" + cl.LineIndex;
                break;

            default:
                iLine = cl.LineIndex;
                return(null);
            }
            return(assembled);
        }
 public static dynamic GetTSObject(ControlLine dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
        /// <summary>
        /// Draw steel lines.
        /// </summary>
        private void DrawSteelLine()
        {
            ControlLine line  = new ControlLine(new Tekla.Structures.Geometry3d.LineSegment(geometricFrame.SteelLineLeftBase, geometricFrame.SteelLineColRaftLftIntrsct), true);
            ControlLine line2 = new ControlLine(new Tekla.Structures.Geometry3d.LineSegment(geometricFrame.SteelLineColRaftLftIntrsct, geometricFrame.SteelLineColRafRghtIntrsct), true);
            ControlLine line3 = new ControlLine(new Tekla.Structures.Geometry3d.LineSegment(geometricFrame.SteelLineColRafRghtIntrsct, geometricFrame.SteelLineRightBase), true);

            line.Insert();
            line2.Insert();
            line3.Insert();
        }
Esempio n. 11
0
 private void LoadSettings()
 {
     foreach (var settings in settingsManager.AllSettings)
     {
         ControlLine cl = controlLinesManager.CreateControlLine(DeleteKeyButton_Click, SubfolderTextBox_TextChanged,
                                                                KeyTextBox_TextChanged, Controls_KeyDown,
                                                                settings.Key, settings.SubfolderName, settings.IsCopyFileMode);
         AddControlLine(cl);
     }
 }
Esempio n. 12
0
 private void AddKeyButton_Click(object sender, RoutedEventArgs e)
 {
     if (controlLinesManager.ControlLinesCount < CONTROL_LINES_COUNT)
     {
         ControlLine cl = controlLinesManager.CreateControlLine(DeleteKeyButton_Click, SubfolderTextBox_TextChanged,
                                                                KeyTextBox_TextChanged,
                                                                Controls_KeyDown);
         AddControlLine(cl);
     }
 }
        public OperationResult Read(IDevice input)
        {
            var operationResult = ControlLine.SendOperation(
                new OperationDto
            {
                Device    = input.Id,
                Operation = 1,
                Params    = new int[] { }
            }
                );
            var result = ErrorService.Validate(operationResult.Status);

            return(new OperationResult
            {
                Return = operationResult.Returns,
                ResultStatus = result
            });
        }
Esempio n. 14
0
        public void WriteRomByte()
        {
            byte address = 0x04;

            var bus         = new Mock <IBus>();
            var controlUnit = new Mock <IControlUnit>();
            var marReg      = new Mock <IRegister>();

            marReg.SetupGet(x => x.Value).Returns(address);

            ControlLine romBank1Line  = new ControlLine(ControlLineId.ROM_BANK_1);
            ControlLine busOutputLine = new ControlLine(ControlLineId.ROM_OUT);

            controlUnit.Setup(x => x.GetControlLine(ControlLineId.ROM_BANK_1)).Returns(romBank1Line);
            controlUnit.Setup(x => x.GetControlLine(ControlLineId.ROM_OUT)).Returns(busOutputLine);

            var rom = new Rom(bus.Object, controlUnit.Object, marReg.Object);

            // You cannot write to ROM
            Assert.Throws <InvalidOperationException>(() => rom.Write(0xFF));
        }
Esempio n. 15
0
        public void ReadValueFromBus(byte expectedValue, SystemRegister registerId, ControlLineId lineId)
        {
            var clock = new Mock <IClock>();

            clock.Setup(x => x.AddConnectedComponent(It.IsAny <IClockConnectedComponent>()));

            var bus = new Mock <IBus>();

            bus.SetupGet(x => x.Value).Returns(expectedValue);

            var controlUnit = new Mock <IControlUnit>();

            ControlLine busInputLine = new ControlLine(lineId);

            controlUnit.Setup(x => x.GetControlLine(lineId)).Returns(busInputLine);

            Register reg = new Register(registerId, clock.Object, bus.Object, controlUnit.Object);

            busInputLine.State = true;
            reg.OnRisingEdge();

            // Register has it's input line high so should read the value currently on the bus
            Assert.Equal(expectedValue, reg.Value);
        }
Esempio n. 16
0
        public void NoBusRead(byte expectedValue, SystemRegister registerId, ControlLineId lineId)
        {
            var clock = new Mock <IClock>();

            clock.Setup(x => x.AddConnectedComponent(It.IsAny <IClockConnectedComponent>()));

            var bus = new Mock <IBus>();

            bus.SetupGet(x => x.Value).Returns(expectedValue);

            var controlUnit = new Mock <IControlUnit>();

            ControlLine busInputLine = new ControlLine(lineId);

            controlUnit.Setup(x => x.GetControlLine(lineId)).Returns(busInputLine);

            Register reg = new Register(registerId, clock.Object, bus.Object, controlUnit.Object);

            busInputLine.State = false;
            reg.OnRisingEdge();

            // A register should not read a value when it's controlline is low
            Assert.Equal(0, reg.Value);
        }
Esempio n. 17
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (MyModel.GetConnectionStatus())
            {
                double off1 = Convert.ToDouble(textBox4.Text);
                double off2 = Convert.ToDouble(textBox5.Text);
                TransformationPlane currentPlane = MyModel.GetWorkPlaneHandler().GetCurrentTransformationPlane();
                Picker piku = new Picker();

                ArrayList info = new ArrayList();
                info = new ArrayList {
                    "END_X", "END_Y", "END_Z", "START_X", "START_Y", "START_Z"
                };
                ArrayList info2 = new ArrayList();
                info2 = new ArrayList {
                    "END_X", "END_Y", "END_Z", "START_X", "START_Y", "START_Z"
                };
                ModelObject part  = new Beam();
                ModelObject part2 = new Beam();
                Hashtable   p1    = new Hashtable();
                Hashtable   p2    = new Hashtable();
                part = piku.PickObject(Picker.PickObjectEnum.PICK_ONE_PART);
                part.GetDoubleReportProperties(info, ref p1);
                double rotpart = (part as Part).Position.RotationOffset;
                part2 = piku.PickObject(Picker.PickObjectEnum.PICK_ONE_PART);
                part2.GetDoubleReportProperties(info2, ref p2);
                double rotpart2 = (part2 as Part).Position.RotationOffset;


                Point st1 = new Point(Convert.ToDouble(p1["START_X"]), Convert.ToDouble(p1["START_Y"]), Convert.ToDouble(p1["START_Z"]));
                Point st2 = new Point(Convert.ToDouble(p2["END_X"]), Convert.ToDouble(p2["END_Y"]), Convert.ToDouble(p2["END_Z"]));
                Point st3 = new Point(Convert.ToDouble(p1["END_X"]), Convert.ToDouble(p1["END_Y"]), Convert.ToDouble(p1["END_Z"]));
                Point st4 = new Point(Convert.ToDouble(p2["START_X"]), Convert.ToDouble(p2["START_Y"]), Convert.ToDouble(p2["START_Z"]));

                LineSegment l1 = new LineSegment(st1, st2);
                LineSegment l3 = new LineSegment(st1, st3); Vector vl3 = l3.GetDirectionVector(); vl3.Normalize();
                LineSegment l4 = new LineSegment(st2, st1);
                LineSegment l5 = new LineSegment(st2, st4); Vector vl5 = l5.GetDirectionVector(); vl5.Normalize();

                st1.Translate(vl3.X * (off1 / vl3.GetLength()), vl3.Y * (off1 / vl3.GetLength()), vl3.Z * (off1 / vl3.GetLength()));
                st2.Translate(vl5.X * (off2 / vl5.GetLength()), vl5.Y * (off2 / vl5.GetLength()), vl5.Z * (off2 / vl5.GetLength()));


                ControlLine cl1 = new ControlLine(l1, true);
                cl1.Color = ControlLine.ControlLineColorEnum.YELLOW_RED;

                //cl1.Insert();

                CoordinateSystem cs1 = new CoordinateSystem();
                cs1 = part.GetCoordinateSystem();
                CoordinateSystem cs2 = new CoordinateSystem();
                cs2 = part2.GetCoordinateSystem();

                Tekla.Structures.Model.Plane pl1 = new Tekla.Structures.Model.Plane();
                pl1.AxisX  = cs1.AxisX;
                pl1.AxisY  = cs1.AxisY;
                pl1.Origin = cs1.Origin;

                Tekla.Structures.Model.Plane pl2 = new Tekla.Structures.Model.Plane();
                pl2.AxisX  = cs2.AxisX;
                pl2.AxisY  = cs2.AxisY;
                pl2.Origin = cs2.Origin;

                GeometricPlane gp1 = new GeometricPlane(cs1);
                GeometricPlane gp2 = new GeometricPlane(cs2);

                ControlPlane cp1 = new ControlPlane(pl1, true);
                //cp1.Insert();
                ControlPlane cp2 = new ControlPlane(pl2, true);
                //cp2.Insert();

                LineSegment l2 = Projection.LineSegmentToPlane(l1, gp1);
                LineSegment l6 = Projection.LineSegmentToPlane(l4, gp2);

                ControlLine cl2 = new ControlLine(l2, true);
                ControlLine cl3 = new ControlLine(l6, true);


                cl2.Color = ControlLine.ControlLineColorEnum.YELLOW_RED;
                //cl2.Insert();
                cl3.Color = ControlLine.ControlLineColorEnum.YELLOW_RED;
                //cl3.Insert();

                Part         p3   = part as Part;
                Solid        sl1  = p3.GetSolid();
                ArrayList    al1  = sl1.Intersect(l2);
                Point        px   = new Point(al1[1] as Point);
                ControlPoint cpp1 = new ControlPoint(px);
                //cpp1.Insert();

                Part         p4   = part2 as Part;
                Solid        sl2  = p4.GetSolid();
                ArrayList    al2  = sl2.Intersect(l6);
                Point        py   = new Point(al2[1] as Point);
                ControlPoint cpp4 = new ControlPoint(py);
                //cpp4.Insert();

                double distance  = Distance.PointToLineSegment(st3, l2);
                double distance1 = l3.Length();
                double cos       = distance / distance1;
                double distance2 = Distance.PointToLineSegment(st4, l6);
                double distance3 = l5.Length();
                double cos1      = distance2 / distance3;

                Point        p10  = dlugosc(st1, st3, 4, cos, px);
                ControlPoint cpp2 = new ControlPoint(p10);
                //cpp2.Insert();
                Point        p20  = dlugosc(st2, st4, 4, cos1, py);
                ControlPoint cpp5 = new ControlPoint(p20);
                //cpp5.Insert();


                Point  p5   = new Point(l2.StartPoint);
                Point  p6   = new Point(l2.EndPoint);
                Vector v1   = new Vector((p6.X - p5.X) / 10000, (p6.Y - p5.Y) / 10000, (p6.Z - p5.Z) / 10000);
                double v1d  = v1.GetLength();
                double dlbl = Convert.ToDouble(textBox2.Text);
                Point  p11  = new Point(px);
                p11.Translate(v1.X * (dlbl / v1d), v1.Y * (dlbl / v1d), v1.Z * (dlbl / v1d));
                Point        p12  = dlugosc(st1, st3, 4, cos, p11);
                ControlPoint cpp3 = new ControlPoint(p12);
                //cpp3.Insert();
                Point  p7    = new Point(l6.StartPoint);
                Point  p8    = new Point(l6.EndPoint);
                Vector v2    = new Vector((p8.X - p7.X) / 10000, (p8.Y - p7.Y) / 10000, (p8.Z - p7.Z) / 10000);
                double v2d   = v2.GetLength();
                double dlbl1 = Convert.ToDouble(textBox2.Text);
                Point  p21   = new Point(py);
                p21.Translate(v2.X * (dlbl1 / v2d), v2.Y * (dlbl1 / v2d), v2.Z * (dlbl1 / v2d));
                Point        p22  = dlugosc(st2, st4, 4, cos1, p21);
                ControlPoint cpp6 = new ControlPoint(p22);
                //cpp6.Insert();


                Beam blachast = CreateBlacha(p10, p12, rotpart, 0, textBox1.Text);
                blachast.Insert();
                int        id1  = blachast.Identifier.ID;
                Identifier id11 = new Identifier(id1);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st1, vl3, v1));
                ModelObject blachast3   = MyModel.SelectModelObject(id11);
                double      rotblachast = (blachast3 as Beam).Position.RotationOffset;
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                //textBox1.Text = Convert.ToString(rotblachast);
                blachast.Position.RotationOffset = -rotblachast;
                blachast.PartNumber.Prefix       = "PL";
                blachast.PartNumber.StartNumber  = 1001;
                blachast.Modify();


                Beam blachast2 = CreateBlacha(p20, p22, rotpart2, 1, textBox1.Text);
                blachast2.Insert();
                int        id2  = blachast2.Identifier.ID;
                Identifier id12 = new Identifier(id2);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st2, vl5, v2));
                ModelObject blachast4    = MyModel.SelectModelObject(id12);
                double      rotblachast2 = (blachast4 as Beam).Position.RotationOffset;
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                blachast2.Position.RotationOffset = -rotblachast2;
                blachast2.PartNumber.Prefix       = "PL";
                blachast2.PartNumber.StartNumber  = 1001;
                blachast2.Modify();

                Point p15 = new Point(p12);
                p15.Translate(v1.X * (-30 / v1d), v1.Y * (-30 / v1d), v1.Z * (-30 / v1d));
                ControlPoint cpp7 = new ControlPoint(p15);
                //cpp7.Insert();

                Point p16 = new Point(p22);
                p16.Translate(v2.X * (-30 / v2d), v2.Y * (-30 / v2d), v2.Z * (-30 / v2d));
                ControlPoint cpp8 = new ControlPoint(p16);
                //cpp8.Insert();

                Vector v11516 = new Vector((p16.X - p15.X) / 10000, (p16.Y - p15.Y) / 10000, (p16.Z - p15.Z) / 10000);

                Point p151 = new Point(p15); Point p152 = new Point(p15); Point p153 = new Point(p15);
                Point p161 = new Point(p16); Point p162 = new Point(p16); Point p163 = new Point(p16);

                p151.Translate(v11516.X * (-30 / v11516.GetLength()), v11516.Y * (-30 / v11516.GetLength()), v11516.Z * (-30 / v11516.GetLength()));
                p152.Translate(v11516.X * (120 / v11516.GetLength()), v11516.Y * (120 / v11516.GetLength()), v11516.Z * (120 / v11516.GetLength()));
                p153.Translate(v11516.X * (70 / v11516.GetLength()), v11516.Y * (70 / v11516.GetLength()), v11516.Z * (70 / v11516.GetLength()));

                p161.Translate(v11516.X * (30 / v11516.GetLength()), v11516.Y * (30 / v11516.GetLength()), v11516.Z * (30 / v11516.GetLength()));
                p162.Translate(v11516.X * (-120 / v11516.GetLength()), v11516.Y * (-120 / v11516.GetLength()), v11516.Z * (-120 / v11516.GetLength()));
                p163.Translate(v11516.X * (-70 / v11516.GetLength()), v11516.Y * (-70 / v11516.GetLength()), v11516.Z * (-70 / v11516.GetLength()));

                Beam BlSt1 = BlachaSt(p151, p152, 0);
                BlSt1.Insert();
                int        id3  = BlSt1.Identifier.ID;
                Identifier id13 = new Identifier(id3);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st1, vl3, v1));
                ModelObject blachast5 = MyModel.SelectModelObject(id13);
                double      rot5      = (blachast5 as Beam).Position.RotationOffset;
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                //textBox1.Text = Convert.ToString(rotblachast);
                BlSt1.Position.RotationOffset = -rot5;
                BlSt1.PartNumber.Prefix       = "PL";
                BlSt1.PartNumber.StartNumber  = 1001;
                BlSt1.Modify();

                Beam BlSt2 = BlachaSt(p161, p162, 1);
                BlSt2.Insert();
                int        id4  = BlSt2.Identifier.ID;
                Identifier id14 = new Identifier(id4);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st2, vl5, v2));
                ModelObject blachast6 = MyModel.SelectModelObject(id14);
                double      rot6      = (blachast6 as Beam).Position.RotationOffset;
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                //textBox1.Text = Convert.ToString(rotblachast);
                BlSt2.Position.RotationOffset = -rot6;
                BlSt2.PartNumber.Prefix       = "PL";
                BlSt2.PartNumber.StartNumber  = 1001;
                BlSt2.Modify();

                Beam St12 = CreateStezenie12(p153, p163);
                St12.Insert();
                int        id5  = St12.Identifier.ID;
                Identifier id15 = new Identifier(id5);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st1, vl3, v1));
                ModelObject stezenie1 = MyModel.SelectModelObject(id15);
                (stezenie1 as Beam).StartPointOffset.Dy    = 4;
                (stezenie1 as Part).PartNumber.Prefix      = "Pr";
                (stezenie1 as Part).PartNumber.StartNumber = 1001;
                stezenie1.Modify();
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st2, vl5, v2));
                ModelObject stezenie2 = MyModel.SelectModelObject(id15);
                (stezenie2 as Beam).EndPointOffset.Dy      = -6;
                (stezenie2 as Part).PartNumber.Prefix      = "Pr";
                (stezenie2 as Part).PartNumber.StartNumber = 1001;
                stezenie2.Modify();
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);

                double split      = Convert.ToDouble(textBox3.Text);
                Point  pointsplit = new Point(p163);
                pointsplit.Translate(v11516.X * (-split / v11516.GetLength()), v11516.Y * (-split / v11516.GetLength()), v11516.Z * (-split / v11516.GetLength()));


                BoltArray b1 = sruby(p151, p152, BlSt1, blachast);
                b1.Insert();
                int        id6  = b1.Identifier.ID;
                Identifier id16 = new Identifier(id6);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st1, vl3, v1));
                ModelObject b1m = MyModel.SelectModelObject(id16);
                (b1m as BoltArray).Position.RotationOffset = 0;
                (b1m as BoltArray).BoltStandard            = "4017-8.8";
                (b1m as BoltArray).ExtraLength             = 5;
                b1m.Modify();
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);

                BoltArray b2 = sruby(p161, p162, BlSt2, blachast2);
                b2.Insert();
                int        id7  = b2.Identifier.ID;
                Identifier id17 = new Identifier(id7);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st2, vl5, v2));
                ModelObject b2m = MyModel.SelectModelObject(id17);
                (b2m as BoltArray).Position.RotationOffset = 180;
                b2m.Modify();
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);


                Weld w  = new Weld();
                Weld w2 = new Weld();
                Weld w3 = new Weld();
                Weld w4 = new Weld();
                w.MainObject      = stezenie2;
                w.SecondaryObject = BlSt1;
                w.ShopWeld        = true;
                w.Insert();
                w2.MainObject      = stezenie2;
                w2.SecondaryObject = BlSt2;
                w2.ShopWeld        = true;
                w2.Insert();
                w3.MainObject      = part;
                w3.SecondaryObject = blachast;
                w3.ShopWeld        = true;
                w3.Insert();
                w4.MainObject      = part2;
                w4.SecondaryObject = blachast2;
                w4.ShopWeld        = true;
                w4.Insert();
                Beam       st122 = Operation.Split(stezenie2 as Beam, pointsplit);
                Connection sr    = new Connection();
                sr.Name   = "Połączenie śrubą rzymską";
                sr.Number = 126;
                sr.LoadAttributesFromFile("82269_M12");
                sr.SetPrimaryObject(stezenie2);
                sr.SetSecondaryObject(st122);
                sr.Insert();
            }


            MyModel.CommitChanges();
        }
Esempio n. 18
0
 private void AddControlLine(ControlLine cl)
 {
     SettingsGrid.RowDefinitions.Add(cl.ControlRow);
     SettingsGrid.Children.Add(cl.ControlStackPanel);
 }
Esempio n. 19
0
        /// <summary>
        /// 播放器调用方法
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>


        public static ToolboxItem GetToolBoxItemPreview(SaveItemInfo info)
        {
            TransformGroup   transformGroup;
            WindowsFormsHost winformHost;


            string      TempPath = "";
            Image       image;
            ToolboxItem item = null;

            item           = new ToolboxItem();
            item.AssetType = info.assetType;
            item.ItemId    = info.ItemId;
            item.ItemName  = info.ItemName;

            if (!string.IsNullOrEmpty(info.AssetPath))
            {
                TempPath = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Temp" + info.AssetPath.Substring(info.AssetPath.LastIndexOf("\\"));
                //MessageBox.Show("getitem,"+TempPath);
                try
                {
                    if (System.IO.File.Exists(TempPath))
                    {
                        System.IO.File.Delete(TempPath);
                    }

                    if (!info.IsDescPt || info.assetType == AssetType.HTML5)
                    {
                        FileSecurity.StreamToFileInfo(TempPath, info.AssetPath);
                        if (info.assetType == AssetType.HTML5)
                        {
                            string ItemdisFile = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Temp" + "\\" + info.ItemsDis.Substring(info.ItemsDis.LastIndexOf("\\"));
                            if (Directory.Exists(ItemdisFile))
                            {
                                DirectoryInfo di = new DirectoryInfo(ItemdisFile);
                                di.Delete(true);
                            }

                            Directory.CreateDirectory(ItemdisFile);
                            string TempFile = ItemdisFile + "\\";

                            string DecFile = info.ItemsDis.Substring(0, info.ItemsDis.LastIndexOf("\\") + 1);


                            GZip.Decompress(DecFile, TempFile, info.ItemsDis.Substring(info.ItemsDis.LastIndexOf("\\") + 1) + ".zip");
                        }
                    }

                    else
                    {
                        FileSecurity.decryptFile(Globals.AssetDecryptKey, TempPath, info.AssetPath);
                    }
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message);
                    //log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    //log.Error(ex.Message + "\r\n" + ex.StackTrace);
                }


                Globals.tempFileList.Add(TempPath);
                //info.AssetPath = TempPath;
            }
            switch (info.assetType)
            {
            case AssetType.Movie:

                Control.ControlMediaElement mediaElement = new Control.ControlMediaElement();
                mediaElement.Source = new Uri(TempPath, UriKind.Absolute);
                mediaElement.mediaElement.LoadedBehavior   = MediaState.Manual;
                mediaElement.mediaElement.UnloadedBehavior = MediaState.Stop;

                //mediaElement.Stop();
                item.Content = mediaElement;

                break;

            case AssetType.Sound:
                MediaPlayer mediaPlayer = new MediaPlayer();
                mediaPlayer.Open(new Uri(TempPath, UriKind.Absolute));
                mediaPlayer.Stop();
                item.Content    = mediaPlayer;
                item.Visibility = Visibility.Hidden;
                break;

            case AssetType.Topic:
                System.Collections.Generic.List <int> answerList = new System.Collections.Generic.List <int>();

                TopicInfo topicInfo = XamlReader.Load(XmlReader.Create((TextReader) new StringReader(((ContentText)info.Content).Text))) as TopicInfo;
                foreach (var v in topicInfo.TopicOptionList)    //记录正确答案。
                {
                    if (v.Right)
                    {
                        answerList.Add(v.Id);
                    }
                }
                TopicControl tc = new TopicControl(false, answerList);
                tc.TopicInfo = topicInfo;
                tc.Clear();
                //tc.TopicInfo.TopicOptionList[0].Right = true;
                //foreach (var v in tc.TopicInfo.TopicOptionList)
                //    v.IsSelected = false;

                SetShowDiv(info, item, tc);
                break;

            case AssetType.TopicDrag:
                ContentTopicDrag contentTopicDrag = info.Content as ContentTopicDrag;
                if (contentTopicDrag == null)
                {
                    break;
                }
                ControlTopicDrag controlTopicDarg = new ControlTopicDrag(contentTopicDrag.topicDragItemAnswerList, contentTopicDrag.topicDragItemList,
                                                                         new SolidColorBrush((Color)ColorConverter.ConvertFromString(contentTopicDrag.Background)),
                                                                         new SolidColorBrush((Color)ColorConverter.ConvertFromString(contentTopicDrag.Foreground)), false);
                controlTopicDarg.Score = info.Score;

                SetShowDiv(info, item, controlTopicDarg);
                break;

            case AssetType.Text:
                System.Windows.Controls.RichTextBox richtextbox = new System.Windows.Controls.RichTextBox();
                richtextbox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                richtextbox.BorderThickness             = new Thickness(0);
                richtextbox.IsReadOnly = true;

                richtextbox.Document   = XamlReader.Load(XmlReader.Create((TextReader) new StringReader(jg.HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(((ContentText)info.Content).Text, true)))) as FlowDocument;
                richtextbox.Background = richtextbox.Document.Background;
                if (info.LineHeight != 0)
                {
                    richtextbox.Document.LineHeight = info.LineHeight;
                }
                richtextbox.Document.FontSize   = info.FontSize;
                richtextbox.Document.FontFamily = new FontFamily(info.FontFamily);
                item.LineHeight = info.LineHeight;

                SetShowDiv(info, item, richtextbox);
                break;

            case AssetType.TextGrid:
                ControlTextGrid controlTextGrid = new ControlTextGrid();
                controlTextGrid.IsEdit = false;
                controlTextGrid.Source = (ContentGrid)info.Content;

                SetShowDiv(info, item, controlTextGrid);
                item.ItemBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Background));
                item.ItemForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Foreground));

                break;

            case AssetType.Shape:
                System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
                path.Style   = path.FindResource(((ContentText)info.Content).Text) as Style;
                path.Stretch = Stretch.Fill;

                SetShowDiv(info, item, path);
                break;

            case AssetType.Image:

                using (FileStream fs = new FileStream(TempPath, FileMode.Open, FileAccess.Read))
                {
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, (int)fs.Length);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = new MemoryStream(buffer);
                    bitmapImage.EndInit();
                    image = new Image()
                    {
                        Source = bitmapImage
                    };
                    image.Stretch = Stretch.Fill;

                    SetShowDiv(info, item, image);
                }
                break;

            case AssetType.Document:
                WebBrowser webBrowser = new WebBrowser();
                webBrowser.Source = new Uri(TempPath, UriKind.Absolute);
                SetShowDiv(info, item, webBrowser);
                break;

            case AssetType.Message:
                ControlMessage controlMessage = new ControlMessage(false);
                ContentMessage contentMessage = info.Content as ContentMessage;
                if (contentMessage == null)
                {
                    break;
                }
                controlMessage.Title    = contentMessage.Title;
                controlMessage.Location = new Point(contentMessage.PointX, contentMessage.PointY);
                SetShowDiv(info, item, controlMessage);
                break;

            case AssetType.Line:
                ControlLine controlLine = new ControlLine(false);
                ContentLine contentLine = info.Content as ContentLine;
                if (contentLine == null)
                {
                    break;
                }
                controlLine.Point1 = new Point(contentLine.Point1X, contentLine.Point1Y);
                SetShowDiv(info, item, controlLine);
                break;

            case AssetType.HTML5:
                WebBrowerGecko wbgk = new WebBrowerGecko();
                System.Windows.Forms.Integration.WindowsFormsHost w = new System.Windows.Forms.Integration.WindowsFormsHost();
                w.Child = wbgk;
                wbgk.Navigate(TempPath);
                w.SetValue(Panel.ZIndexProperty, 10);
                w.Width      = info.Width;
                w.Height     = info.Height;
                w.Background = new SolidColorBrush(Colors.Red);
                w.Tag        = TempPath;
                item.Content = w;

                break;

            case AssetType.TPageGroup:
                bool dirInfo = false;
                if (DirectoryAssResInfo.Keys.Count > 0)
                {
                    foreach (var v in DirectoryAssResInfo.Keys)
                    {
                        if (v == item.ItemId.ToString())
                        {
                            dirInfo = true;
                            DirectoryAssResInfo[v].Add(TempPath);
                            UpdateImgGroup(DirectoryAssResInfo[v], DirectoryTpage[v]);
                            break;
                        }
                    }
                }
                if (!dirInfo)
                {
                    TPageControl page = new TPageControl();
                    page.Height = info.Height;
                    page.Width  = info.Width;
                    page.canvasPageContent.Width  = info.Width - 100;
                    page.canvasPageContent.Height = info.Height - 2;
                    System.Collections.ObjectModel.ObservableCollection <string> observableAssResInfo = new System.Collections.ObjectModel.ObservableCollection <string>();
                    observableAssResInfo.Add(TempPath);
                    UpdateImgGroup(observableAssResInfo, page);
                    DirectoryAssResInfo.Add(item.ItemId.ToString(), observableAssResInfo);
                    DirectoryTpage.Add(item.ItemId.ToString(), page);
                    item.Content = DirectoryTpage[item.ItemId.ToString()];
                }
                TPageControl tpage = new TPageControl();
                tpage = DirectoryTpage[item.ItemId.ToString()];
                SetShowDiv(info, item, tpage);
                break;
            }



            //item.Opacity = info.Opacity;
            item.AssetPath  = info.AssetPath;
            item.Thumbnails = info.Thumbnails;

            if (info.Background != null)
            {
                item.ItemBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Background));
            }
            if (info.Foreground != null)
            {
                item.ItemForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Foreground));
            }

            item.IsEdit = false;
            item.ItemId = info.ItemId;
            item.Width  = info.Width;
            item.Height = info.Height;

            Canvas.SetLeft(item, info.X);
            Canvas.SetTop(item, info.Y);

            System.Windows.Controls.Panel.SetZIndex(item, info.ZIndex);

            transformGroup = item.RenderTransform as TransformGroup;
            foreach (var v in transformGroup.Children)
            {
                switch (v.GetType().Name)
                {
                case "RotateTransform":
                    ((RotateTransform)v).Angle = info.Angle;
                    break;

                case "ScaleTransform":
                    ((ScaleTransform)v).ScaleX = info.ScaleX == 0 ? 1 : info.ScaleX;
                    ((ScaleTransform)v).ScaleY = info.ScaleY == 0 ? 1 : info.ScaleY;
                    break;

                case "SkewTransform":
                    ((SkewTransform)v).AngleX = info.SkewX;
                    ((SkewTransform)v).AngleY = info.SkewY;
                    break;

                case "TranslateTransform":
                    ((TranslateTransform)v).X = info.TranslateX;
                    ((TranslateTransform)v).Y = info.TranslateY;
                    break;
                }
            }

            return(item);
        }
Esempio n. 20
0
        public static ToolboxItem GetToolBoxItem(SaveItemInfo info)
        {
            Image       image;
            ToolboxItem item = null;

            item           = new ToolboxItem();
            item.AssetType = info.assetType;
            item.ItemName  = info.ItemName;
            item.ItemId    = info.ItemId;
            switch (info.assetType)
            {
            case AssetType.Movie:
            case AssetType.Sound:
            case AssetType.HTML5:
            case AssetType.Document:
                image = new Image()
                {
                    Source = new BitmapImage(new Uri(info.Thumbnails, UriKind.Absolute))
                };
                image.Stretch = Stretch.Fill;
                item.Content  = image;
                break;

            case AssetType.Topic:
                TopicControl tc = new TopicControl(true);
                tc.TopicInfo = XamlReader.Load(XmlReader.Create((TextReader) new StringReader(((ContentText)info.Content).Text))) as TopicInfo;
                item.Content = tc;
                break;

            case AssetType.TopicDrag:
                ContentTopicDrag contentTopicDrag = info.Content as ContentTopicDrag;
                if (contentTopicDrag == null)
                {
                    break;
                }

                ControlTopicDrag controlTopicDarg = new ControlTopicDrag(contentTopicDrag.topicDragItemAnswerList, contentTopicDrag.topicDragItemList,
                                                                         new SolidColorBrush((Color)ColorConverter.ConvertFromString(contentTopicDrag.Background)),
                                                                         new SolidColorBrush((Color)ColorConverter.ConvertFromString(contentTopicDrag.Foreground)), true);
                controlTopicDarg.Score = info.Score;
                item.Content           = controlTopicDarg;
                break;

            case AssetType.Text:
                ControlTextEditor content = new ControlTextEditor();
                if (info.LineHeight != 0)
                {
                    content.mainRTB.Document.LineHeight = info.LineHeight;
                }

                content.mainRTB.Document = XamlReader.Load(XmlReader.Create((TextReader) new StringReader(jg.HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(((ContentText)info.Content).Text, true)))) as FlowDocument;
                //content.mainRTB.Document = XamlReader.Load(XmlReader.Create((TextReader)new StringReader(((ContentText)info.Content).Text))) as FlowDocument;
                if (info.LineHeight != 0)
                {
                    content.mainRTB.Document.LineHeight = info.LineHeight;
                }
                content.mainRTB.Document.FontSize   = info.FontSize;
                content.mainRTB.Document.FontFamily = new FontFamily(info.FontFamily);
                item.LineHeight = info.LineHeight;
                item.FontFamily = new FontFamily(info.FontFamily);
                item.FontSize   = info.FontSize;
                item.Content    = content;
                break;

            case AssetType.TextGrid:
                ControlTextGrid controlTextGrid = new ControlTextGrid();
                controlTextGrid.Source = (ContentGrid)info.Content;
                item.Content           = controlTextGrid;
                break;

            case AssetType.Shape:
                System.Windows.Shapes.Path path = new System.Windows.Shapes.Path()
                {
                    Name = ((ContentText)info.Content).Text
                };
                path.Style   = item.FindResource(((ContentText)info.Content).Text) as Style;
                path.Stretch = Stretch.Fill;
                item.Content = path;
                break;

            case AssetType.Image:
                image = new Image()
                {
                    Source = new BitmapImage(new Uri(info.Thumbnails, UriKind.Absolute))
                };
                image.Stretch = Stretch.Fill;
                item.Content  = image;
                break;

            case AssetType.Message:
                ControlMessage controlMessage = new ControlMessage(true);
                ContentMessage contentMessage = info.Content as ContentMessage;
                if (contentMessage == null)
                {
                    break;
                }
                controlMessage.Title    = contentMessage.Title;
                controlMessage.Location = new Point(contentMessage.PointX, contentMessage.PointY);
                item.Content            = controlMessage;
                break;

            case AssetType.Line:
                ControlLine controlLine = new ControlLine(true);
                ContentLine contentLine = info.Content as ContentLine;
                if (contentLine == null)
                {
                    break;
                }
                controlLine.Point1 = new Point(contentLine.Point1X, contentLine.Point1Y);
                item.Content       = controlLine;
                break;

            case AssetType.TPageGroup:
                bool dirInfo = false;
                if (AssResInfoObser.Keys.Count > 0)
                {
                    foreach (var v in AssResInfoObser.Keys)
                    {
                        if (v == item.ItemId)
                        {
                            dirInfo = true;
                            AssResInfo resInfo = new AssResInfo();
                            resInfo.ArId       = info.ItemId;
                            resInfo.AssetName  = "图片" + (DirectoryTpageLoad[v].Children.Count + 1);
                            resInfo.AssetPath  = info.AssetPath;
                            resInfo.Thumbnails = info.Thumbnails;
                            AssResInfoObser[v].Add(resInfo);
                            DirectoryTpageLoad[v].Children = AssResInfoObser[v];
                            DirectoryTpageLoad[v].UpdateImgGroup();
                            break;
                        }
                    }
                }
                if (!dirInfo)
                {
                    TPageControl page = new TPageControl();
                    page.Height = info.Height;
                    page.Width  = info.Width;
                    page.canvasPageContent.Width  = info.Width - 100;
                    page.canvasPageContent.Height = info.Height - 2;
                    AssResInfo resInfo = new AssResInfo();
                    resInfo.ArId       = info.ItemId;
                    resInfo.AssetName  = "图片1";
                    resInfo.AssetPath  = info.AssetPath;
                    resInfo.Thumbnails = info.Thumbnails;
                    System.Collections.ObjectModel.ObservableCollection <AssResInfo> observableAssResInfo = new System.Collections.ObjectModel.ObservableCollection <AssResInfo>();
                    observableAssResInfo.Add(resInfo);
                    page.Children = observableAssResInfo;
                    page.UpdateImgGroup();
                    AssResInfoObser.Add(item.ItemId, observableAssResInfo);
                    DirectoryTpageLoad.Add(item.ItemId, page);
                    item.Content = DirectoryTpageLoad[item.ItemId];
                }
                break;
            }
            item.IsLongText = info.IsLongText;
            item.IsShowDiv  = info.IsShowDiv;
            item.IsDescPt   = info.IsDescPt;

            item.Opacity = info.Opacity;
            if (info.Background != null)
            {
                item.ItemBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Background));
            }
            if (info.Foreground != null)
            {
                item.ItemForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Foreground));
            }

            item.AssetPath  = info.AssetPath;
            item.Thumbnails = info.Thumbnails;

            return(item);
        }
Esempio n. 21
0
        public override bool Run(List <InputDefinition> Input)
        {
            try
            {
                GetValuesFromDialog();

                WorkPlaneHandler wph = Model.GetWorkPlaneHandler();

                TransformationPlane tp     = wph.GetCurrentTransformationPlane();
                TransformationPlane tppart = null;


                BoltGroup bg = Model.SelectModelObject((Identifier)Input[0].GetInput()) as BoltGroup;
                bg.Select();
                List <Part> parts = new List <Part>();
                parts.Add(bg.PartToBeBolted);
                parts.Add(bg.PartToBoltTo);
                foreach (Part p in bg.OtherPartsToBolt)
                {
                    parts.Add(p);
                }

                #region Clear
                List <Part> _part = new List <Part>();

                foreach (Part p in parts)
                {
                    bool flag = false;
                    foreach (Part pp in _part)
                    {
                        if (pp.Identifier.ID == p.Identifier.ID)
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        _part.Add(p);
                    }
                }

                parts.Clear();
                parts = _part;
                #endregion

                foreach (Part p in parts)
                {
                    if (p is Beam)
                    {
                        Beam b = p as Beam;
                        b.Select();

                        double k = 0.0; b.GetReportProperty("PROFILE.FLANGE_SLOPE_RATIO", ref k);
                        if (k == 0)
                        {
                            continue;
                        }

                        tppart = new TransformationPlane(p.GetCoordinateSystem());
                        wph.SetCurrentTransformationPlane(tppart);
                        bg.Select();
                        foreach (Point pb in bg.BoltPositions)
                        {
                            Point _pb = new Point(pb);

                            #region Уклон полок - точки через солид

                            GeometricPlane gp = new GeometricPlane(
                                _pb,
                                new Vector(0, 1, 0),
                                new Vector(0, 0, 1));
                            List <List <Point> > lp = IntersectSolid(p.GetSolid(), gp);

                            List <LineSegment> ls = new List <LineSegment>();


                            for (int i = 0; i < lp[0].Count - 1; i++)
                            {
                                Point  p1 = lp[0][i];
                                Point  p2 = lp[0][i + 1];
                                Vector v  = new Vector(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
                                v.Normalize(1.0);
                                if (v.Y != 0 && v.Z != 0)
                                {
                                    ControlLine cl = new ControlLine();
                                    cl.Line.Point1 = p1;
                                    cl.Line.Point2 = p2;
                                    // cl.Insert();
                                    ls.Add(new LineSegment(p1, p2));
                                }
                            }

                            Point  _p1 = lp[0][0];
                            Point  _p2 = lp[0][lp[0].Count - 1];
                            Vector _v  = new Vector(_p2.X - _p1.X, _p2.Y - _p1.Y, _p2.Z - _p1.Z);
                            if (_v.Y != 0 && _v.Z != 0)
                            {
                                ls.Add(new LineSegment(_p1, _p2));
                                ControlLine cl = new ControlLine();
                                cl.Line.Point1 = _p1;
                                cl.Line.Point2 = _p2;
                                // cl.Insert();
                            }


                            #endregion

                            #region Точки для построения пластины

                            double diam = bg.BoltSize;

                            double tol = GOST_10906_78[diam][0];
                            double _b  = GOST_10906_78[diam][1];
                            double t1  = GOST_10906_78[diam][2];
                            double t2  = GOST_10906_78[diam][3];

                            int kf = (_pb.Z <= ((Point)b.GetReferenceLine(false)[0]).Z ? -1 : 1);

                            _pb.Z += kf * _b * 0.5;


                            double      h   = double.MaxValue;
                            LineSegment lsb = ls[0];

                            foreach (LineSegment lsi in ls)
                            {
                                double t = Distance.PointToLineSegment(_pb, lsi);
                                if (h >= t)
                                {
                                    h   = t;
                                    lsb = lsi;
                                }
                            }
                            //ControlLine cli = new ControlLine();
                            //cli.Line.Point1 = lsb.Point1;
                            //cli.Line.Point2 = lsb.Point2;
                            //cli.Insert();
                            Point pb1 = new Point(_pb.X, _pb.Y + 1000, _pb.Z);

                            Point pbi = Intersection.LineToLine(
                                new Line(lsb),
                                new Line(_pb, pb1)).Point1;
                            //cli.Line.Point1 = _pb;
                            //cli.Line.Point2 = pbi;
                            //cli.Insert();

                            #endregion

                            ContourPlate cp = new ContourPlate();

                            Contour cr = new Contour();
                            cr.AddContourPoint(new ContourPoint(new Point(pbi.X - _b * 0.5, pbi.Y, pbi.Z), null));

                            cr.AddContourPoint(new ContourPoint(new Point(pbi.X + _b * 0.5, pbi.Y, pbi.Z), null));
                            cr.AddContourPoint(new ContourPoint(new Point(pbi.X + _b * 0.5, pbi.Y, pbi.Z - kf * _b), null));
                            cr.AddContourPoint(new ContourPoint(new Point(pbi.X - _b * 0.5, pbi.Y, pbi.Z - kf * _b), null));

                            cp.Contour = cr;


                            cp.Profile.ProfileString      = "PL" + t1.ToString();
                            cp.AssemblyNumber.Prefix      = prefix_asm;
                            cp.AssemblyNumber.StartNumber = start_part;
                            cp.PartNumber.Prefix          = prefix_part;
                            cp.PartNumber.StartNumber     = start_part;

                            cp.Name = name;
                            cp.Material.MaterialString = material;
                            cp.Finish = finish;

                            if (kf == -1 && pbi.Y > 0)
                            {
                                cp.Position.Depth = Position.DepthEnum.FRONT;
                            }
                            else if (kf == -1 && pbi.Y < 0)
                            {
                                cp.Position.Depth = Position.DepthEnum.BEHIND;
                            }
                            else if (kf == 1 && pbi.Y > 0)
                            {
                                cp.Position.Depth = Position.DepthEnum.BEHIND;
                            }
                            else if (kf == 1 && pbi.Y < 0)
                            {
                                cp.Position.Depth = Position.DepthEnum.FRONT;
                            }

                            cp.Insert();

                            if (weight != 0.0 && us_prop_weight != "")
                            {
                                cp.SetUserProperty(us_prop_weight, weight);
                                cp.Modify();
                            }

                            BooleanPart  bp  = new BooleanPart();
                            ContourPlate cp2 = new ContourPlate();
                            Contour      cr2 = new Contour();

                            cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y, pbi.Z), null));
                            cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y, pbi.Z - kf * _b), null));
                            cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y + (pbi.Y > 0 ? -1 * (t1 - t2) : (t1 - t2)), pbi.Z - kf * _b), null));

                            cp2.Contour = cr2;
                            cp2.Profile.ProfileString = "PL" + (_b + 10).ToString();
                            cp2.Class = BooleanPart.BooleanOperativeClassName;

                            cp2.Insert();

                            bp.Father        = cp;
                            bp.OperativePart = cp2;
                            bp.Insert();
                            cp2.Delete();

                            BoltArray ba = new BoltArray();
                            ba.FirstPosition  = pb;
                            ba.SecondPosition = new Point(pb.X + 100, pb.Y, pb.Z);

                            ba.BoltStandard      = bg.BoltStandard;
                            ba.Position.Rotation = Position.RotationEnum.TOP;
                            ba.BoltType          = bg.BoltType;
                            ba.BoltSize          = bg.BoltSize;
                            ba.Tolerance         = tol;
                            ba.Bolt = false;
                            ba.AddBoltDistX(0);
                            ba.AddBoltDistY(0);
                            ba.PartToBeBolted = cp;
                            ba.PartToBoltTo   = cp;
                            ba.Insert();
                        }
                    }
                }
                wph.SetCurrentTransformationPlane(tp);
            }
            catch (Exception Exc)
            {
                MessageBox.Show(Exc.ToString());
            }

            return(true);
        }