public StepFile Read(byte[] file, string fileExtension)
        {
            StepFile stepFile = null;

            if (this.stepFileReader.ContainsKey(fileExtension))
            {
                stepFile = this.stepFileReader[fileExtension].Read(file);
            }

            return(stepFile);
        }
 public void FailUponBadPath()
 {
     try
     {
         var converter = new StepFile("bad-path-no-file");
         Assert.NotNull(converter);
     }
     catch (Exception e)
     {
         // passed.
     }
 }
        public void WriteLineTest()
        {
            var file = new StepFile();

            file.Items.Add(new StepLine("", new StepCartesianPoint("", 1.0, 2.0, 3.0), new StepVector("", new StepDirection("", 1.0, 0.0, 0.0), 4.0)));
            AssertFileContains(file, @"
#1=CARTESIAN_POINT('',(1.0,2.0,3.0));
#2=DIRECTION('',(1.0,0.0,0.0));
#3=VECTOR('',#2,4.0);
#4=LINE('',#1,#3);
");
        }
        public void CanCorrectlyDeserializeAmbiguousNumber()
        {
            StepReader            sr      = createStepReader(ExampleData.AmbiguousNumberString());
            StepFile              result  = SUT.Deserialize(sr);
            List <StepDataObject> values  = new List <StepDataObject>(result.Data.Values);
            StepDataObject        entity0 = values[0];

            Assert.IsNotNull(entity0);
            Assert.IsNotNull(entity0.Properties);
            Assert.AreEqual(1, entity0.Properties.Count);
            AssertFloat(1E-5, entity0.Properties[0]);
        }
Exemple #5
0
        public ActionResult EditStepFile(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StepFile stepfile = db.StepFiles.Find(id);

            if (stepfile == null)
            {
                return(HttpNotFound());
            }
            return(View(stepfile));
        }
Exemple #6
0
        private StepFile ReadFileFromHeader(string header)
        {
            var file = $@"
{StepFile.MagicHeader};
{StepFile.HeaderText};
{header.Trim()}
{StepFile.EndSectionText};
{StepFile.DataText};
{StepFile.EndSectionText};
{StepFile.MagicFooter};
";

            return(StepFile.Parse(file.Trim()));
        }
Exemple #7
0
        public ConvertSmCommand(string[] args) : base(args)
        {
            OutputPath = args[2];
            Directory.CreateDirectory(OutputPath);

            Converter = new StepFile(args[1]);

            var quas = Converter.ToQuas();

            for (var i = 0; i < quas.Count; i++)
            {
                quas[i].Save($"{OutputPath}/{i}.qua");
            }
        }
Exemple #8
0
 public ActionResult CreateStepFile([Bind(Include = "StepFileId,FileName,FilePath,TemplateId")] StepFile stepfile)
 {
     if (ModelState.IsValid)
     {
         stepfile.FilePath = "C:\\RunRemote\\" + stepfile.FileName;
         db.StepFiles.Add(stepfile);
         db.SaveChanges();
         StepFile steptemplate = db.StepFiles.Find(stepfile.TemplateId);
         FileCopy(steptemplate.FilePath, stepfile.FilePath);
         return(RedirectToAction("Index"));
     }
     PopulateStepFileTemplatesDropDownList(stepfile.Id);
     return(View(stepfile));
 }
Exemple #9
0
        public bool ReadDrawing(string fileName, Stream fileStream, out Drawing drawing, out ViewPort viewPort)
        {
            var layer = new Layer("step");
            var file  = StepFile.Load(fileStream);

            foreach (var item in file.GetTopLevelItems())
            {
                switch (item.ItemType)
                {
                case StepItemType.Circle:
                {
                    var stepCircle = (StepCircle)item;
                    var center     = ToPoint(stepCircle.Position.Location);
                    var normal     = stepCircle.Position is StepAxis2Placement3D
                                ? ToVector(((StepAxis2Placement3D)stepCircle.Position).Axis)
                                : Vector.ZAxis;

                    var circle = new Circle(center, stepCircle.Radius, normal);
                    layer = layer.Add(circle);
                    break;
                }

                case StepItemType.EdgeCurve:
                {
                    layer = layer.Add(ToEntity((StepEdge)item));
                    break;
                }

                case StepItemType.Line:
                {
                    var line = ToLine((StepLine)item);
                    layer = layer.Add(line);
                    break;
                }

                case StepItemType.OrientedEdge:
                {
                    var orientedEdge = (StepOrientedEdge)item;
                    layer = layer.Add(ToEntity(orientedEdge.EdgeElement));
                    break;
                }
                }
            }

            drawing  = new Drawing().Add(layer);
            viewPort = null;

            return(true);
        }
Exemple #10
0
        public void CanWriteFile()
        {
            StepFileReader reader   = new StepFileReader();
            StepFile       stepFile = reader.Read(SIM_FILE_RENAISSANCE);


            string testFileName = "test.sm";

            StepFileWriter writer = new StepFileWriter();

            writer.Write(stepFile, testFileName);


            Assert.IsTrue(File.Exists(testFileName));
        }
Exemple #11
0
        /// <summary>
        /// Deserializes STEP format data by reading stream provided by a StreamReader.  An iso_10303 object is returned.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public iso_10303 Deserialize(IStepReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            this._internalDeserializer = new StepDeserializer();
            this._binder = new StepBinder();
            StepFile stepFile = this._internalDeserializer.Deserialize(reader);

            iso_10303 iso10303 = this._binder.Bind(stepFile);

            return(iso10303);
        }
        private StepFile ReadFile(string data)
        {
            var text = $@"
ISO-10303-21;
HEADER;
ENDSEC;
DATA;
{data.Trim()}
ENDSEC;
END-ISO-10303-21;
";
            var file = StepFile.Parse(text.Trim());

            return(file);
        }
        public void ConvertToQuaFile()
        {
            var dir = "./tests/sm";

            Directory.CreateDirectory(dir);

            var converter = new StepFile("./Stepmania/Resources/chaoz-airflow.sm");
            var quas      = converter.ToQuas();


            for (var i = 0; i < quas.Count; i++)
            {
                quas[i].Save($"{dir}/{i}.qua");
            }
        }
Exemple #14
0
        public Task <ReadDrawingResult> ReadDrawing(string fileName, Stream fileStream, Func <string, Task <byte[]> > contentResolver)
        {
            var layer = new Layer("step");
            var file  = StepFile.Load(fileStream);

            foreach (var item in file.GetTopLevelItems())
            {
                switch (item.ItemType)
                {
                case StepItemType.Circle:
                {
                    var stepCircle = (StepCircle)item;
                    var center     = ToPoint(stepCircle.Position.Location);
                    var normal     = stepCircle.Position is StepAxis2Placement3D
                                ? ToVector(((StepAxis2Placement3D)stepCircle.Position).Axis)
                                : Vector.ZAxis;

                    var circle = new Circle(center, stepCircle.Radius, normal);
                    layer = layer.Add(circle);
                    break;
                }

                case StepItemType.EdgeCurve:
                {
                    layer = layer.Add(ToEntity((StepEdge)item));
                    break;
                }

                case StepItemType.Line:
                {
                    var line = ToLine((StepLine)item);
                    layer = layer.Add(line);
                    break;
                }

                case StepItemType.OrientedEdge:
                {
                    var orientedEdge = (StepOrientedEdge)item;
                    layer = layer.Add(ToEntity(orientedEdge.EdgeElement));
                    break;
                }
                }
            }

            var drawing = new Drawing().Add(layer);

            return(Task.FromResult(ReadDrawingResult.Succeeded(drawing, null)));
        }
Exemple #15
0
        public void Serialize(IStepWriter writer, StepFile step)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (step == null)
            {
                throw new ArgumentNullException("step");
            }

            writer.WriteStartStep();
            SerializeHeader(writer, step.Header);
            SerializeData(writer, step.Data);
            writer.WriteEndStep();
        }
Exemple #16
0
        public void SaveStepFile(Step step)
        {
            StepFile stepfile = db.StepFiles.Find(step.StepFileId);
            //Step step = db.Steps.Find(id);
            int snum = 0, cnum = 0;

            List <StepQueue> stepqueues = db.StepQueues.Where(p => p.StepFile.Id == stepfile.Id).OrderBy(s => s.StepId).ToList();

            for (int i = 0; i < stepqueues.Count; i++)
            {
                if (stepqueues[i].State == "Server")
                {
                    snum++;
                }
                if (stepqueues[i].State == "Client")
                {
                    cnum++;
                }
            }
            step.Server = new Server[snum];
            step.Client = new Client[cnum];
            for (int k = 0, i = 0, j = 0; k < stepqueues.Count; k++)
            {
                if (stepqueues[k].State == "Server")
                {
                    step.Server[i]       = new Server();
                    step.Server[i].Name  = stepqueues[k].StepName;
                    step.Server[i].Value = stepqueues[k].StepValue;
                    i++;
                }
                if (stepqueues[k].State == "Client")
                {
                    step.Client[j]       = new Client();
                    step.Client[j].Name  = stepqueues[k].StepName;
                    step.Client[j].Value = stepqueues[k].StepValue;
                    j++;
                }
            }

            var json = JsonConvert.SerializeObject(step);

            if (System.IO.File.Exists(stepfile.FilePath))
            {
                System.IO.File.WriteAllText(stepfile.FilePath, json);
            }
        }
Exemple #17
0
        public void WriteHeaderWithLongDescriptionTest()
        {
            var file = new StepFile();

            file.Description = new string('a', 257);
            file.Timestamp   = new DateTime(2010, 1, 1);
            file.Schemas.Add(StepSchemaTypes.ExplicitDraughting);
            AssertFileIs(file, $@"
ISO-10303-21;
HEADER;
FILE_DESCRIPTION(('{new string('a', 256)}','a'),'');
FILE_NAME('','2010-01-01T00:00:00.0000000',(''),(''),'','','');
FILE_SCHEMA(('EXPLICIT_DRAUGHTING'));
ENDSEC;
DATA;
ENDSEC;
END-ISO-10303-21;
".TrimStart());
        }
Exemple #18
0
        /// <summary>
        /// Serializes an iso_10303 object into STEP format, writing the data to the given StepWriter
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="iso10303"></param>
        public void Serialize(IStepWriter writer, iso_10303 iso10303)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (iso10303 == null)
            {
                throw new ArgumentNullException("iso10303");
            }

            this._internalSerializer = new StepParser.Serialization.StepSerializer();
            this._extractor          = new StepObjectExtractor();

            //Convert from iso_10303 to StepDataObjects
            StepFile stepFile = this._extractor.Extract(iso10303);

            //use the InternalStepSerializer to write StepDataObjects to the StepWriter
            this._internalSerializer.Serialize(writer, stepFile);
        }
    public void MySampelMethod()
    {
        // This will create the following CAD hierarchy:
        //-------------------------------------------------
        //
        //   + MyRootAssembly       [assembly root]
        //   |
        //   +---+- sample-group    [empty part]
        //       |
        //       +- sample-box      [part with box geometry]
        //

        // example file path where the STEP file will be written
        const string FILEPATH = @"C:\Users\me\Documents\file.step";

        // create new StepFile instance
        StepFile stepFile = new StepFile(FILEPATH, "MyRootAssembly");

        // add a Group to StepFile and get the groups id
        int groupId = stepFile.AddGroup(
            name: "sample-group",                       // name of the part
            position: new Vector3(0, 0, 0),             // Group position relative to parent position
            rotation: new Vector3(90, 0, 0),            // Group rotation relative to parent rotation
            parentId: stepFile.ASSEMBLY_ROOT_ID         // id of parent object (ASSEMBLY_ROOT_ID is 0)
            );

        // add a Box to StepFile
        stepFile.AddBox(
            name: "sample-box",                         // name of the part
            position: new Vector3(0, 0, 0),             // Box position (based on the center of the box) relative to parent position
            dimension: new Vector3(10, 10, 10),         // dimension of the box (length, width, height)
            rotation: new Vector3(0, 0, 0),             // Box rotation (rotated around box center) relative to parent rotation
            color: Color.Red,                           // color of the Box
            parentId: groupId                           // id of the parent object
            );

        // write the StepFile to file system
        bool result = stepFile.WriteFile();
    }
 public void Write(StepFile stepFile, string destinationPath)
 {
     if (stepFile.IsValid())
     {
         using (FileStream fileStream = new FileStream(destinationPath, FileMode.CreateNew, FileAccess.Write))
         {
             using (BinaryWriter binaryWriter = new BinaryWriter(fileStream, Encoding.UTF8))
             {
                 this.WriteProperty("TITLE", stepFile.Title, binaryWriter);
                 this.WriteProperty("SUBTITLE", "", binaryWriter);
                 this.WriteProperty("ARTIST", stepFile.Artist, binaryWriter);
                 this.WriteProperty("TITLETRANSLIT", "", binaryWriter);
                 this.WriteProperty("SUBTITLETRANSLIT", "", binaryWriter);
                 this.WriteProperty("ARTISTTRANSLIT", "", binaryWriter);
                 this.WriteProperty("GENRE", "", binaryWriter);
                 this.WriteProperty("CREDIT", "", binaryWriter);
                 this.WriteProperty("BANNER", "", binaryWriter);
                 this.WriteProperty("BACKGROUND", "", binaryWriter);
                 this.WriteProperty("LYRICSPATH", "", binaryWriter);
                 this.WriteProperty("CDTITLE", "", binaryWriter);
                 this.WriteProperty("MUSIC", "", binaryWriter);
                 this.WriteProperty("OFFSET", "", binaryWriter);
                 this.WriteProperty("BPMS", this.WriteTimings(stepFile.BPMs), binaryWriter);
                 this.WriteProperty("STOPS", this.WriteTimings(stepFile.Stops), binaryWriter);
                 this.WriteProperty("SAMPLESTART", "", binaryWriter);
                 this.WriteProperty("SAMPLELENGTH", "", binaryWriter);
                 this.WriteProperty("DISPLAYBPM", "", binaryWriter);
                 this.WriteProperty("SELECTABLE", "", binaryWriter);
                 this.WriteProperty("BGCHANGES", "", binaryWriter);
                 this.WriteProperty("FGCHANGES", "", binaryWriter);
                 this.WriteNotes(stepFile, binaryWriter);
             }
         }
     }
     else
     {
         // not valid
     }
 }
Exemple #21
0
        // GET: Step
        public ActionResult Index(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StepFile stepfile = db.StepFiles.Find(id);

            if (stepfile == null)
            {
                return(HttpNotFound());
            }
            string json = "";

            if (System.IO.File.Exists(stepfile.FilePath))
            {
                json = System.IO.File.ReadAllText(stepfile.FilePath);
            }

            if (db.Steps.FirstOrDefault(p => p.StepFileId == stepfile.Id) == null)
            {
                Step stepjson = JsonConvert.DeserializeObject <Step>(json);
                stepjson.StepFileId = stepfile.Id;
                db.Steps.Add(stepjson);
                db.SaveChanges();
            }
            Step step = db.Steps.Single(p => p.StepFileId == stepfile.Id);

            if (db.StepQueues.Where(p => p.StepFile.Id == stepfile.Id).Count() == 0)
            {
                SaveQueue(step, stepfile);
            }
            dynamic model = new ExpandoObject();

            model.Step       = step;
            model.StepFile   = stepfile;
            model.StepQueues = db.StepQueues.Where(p => p.StepFile.Id == stepfile.Id).OrderBy(s => s.StepId);
            return(View(model));
        }
        public StepFile Read(byte[] file)
        {
            // A .sm file is primarily composed of two major sections: the header, and the chart data.
            // The .sm file format is mostly a key/value store, though the actual note and chart data is a bit more complex.

            StepFile stepFile = new StepFile();
            Dictionary <string, string> simFileMetaEntries = new Dictionary <string, string>();
            List <string> simNoteEntries = new List <string>();

            if (file != null)
            {
                using (MemoryStream stream = new MemoryStream(file))
                {
                    int symbol;
                    while ((symbol = stream.ReadByte()) >= 0)
                    {
                        if (symbol == HASHTAG)
                        {
                            string key   = this.ReadTillChar(stream, COLON);
                            string value = this.ReadTillChar(stream, SEMICOLON);
                            if (key == NOTE_KEY)
                            {
                                simNoteEntries.Add(value);
                            }
                            else
                            {
                                simFileMetaEntries.Add(key, value);
                            }
                        }
                    }
                }

                this.ParseMeta(simFileMetaEntries, stepFile);
                this.ParseNotes(simNoteEntries, stepFile);
            }

            return(stepFile);
        }
Exemple #23
0
        public void SaveQueue(Step step, StepFile stepfile)
        {
            if (step == null)
            {
                return;
            }
            int i = 1;

            foreach (var server in step.Server)
            {
                db.StepQueues.Add(new StepQueue {
                    StepId = 1000 * i, StepName = server.Name, StepValue = server.Value, StepFile = stepfile, State = "Server"
                });
                i = i + 1;
            }
            foreach (var client in step.Client)
            {
                db.StepQueues.Add(new StepQueue {
                    StepId = 1000 * i, StepName = client.Name, StepValue = client.Value, StepFile = stepfile, State = "Client"
                });
                i = i + 1;
            }
            db.SaveChanges();
        }
        private void ParseMeta(Dictionary <string, string> simFileMetaEntries, StepFile stepFile)
        {
            // Header Tags
            // The header tags are song - specific and are shared between all charts. Most header tags follow the format #TAG:VALUE;, though some tags have their own format.

            // Sets the primary title of the song.
            if (simFileMetaEntries.ContainsKey("TITLE"))
            {
                stepFile.Title = simFileMetaEntries["TITLE"];
            }

            // Sets the subtitle of the song.
            if (simFileMetaEntries.ContainsKey("SUBTITLE"))
            {
            }

            // Sets the artist of the song.
            if (simFileMetaEntries.ContainsKey("ARTIST"))
            {
                stepFile.Artist = simFileMetaEntries["ARTIST"];
            }

            // Sets the transliterated primary title of the song, used when ShowNativeLanguage = 0.
            if (simFileMetaEntries.ContainsKey("TITLETRANSLIT"))
            {
            }

            // Sets the transliterated subtitle of the song, used when ShowNativeLanguage = 0.
            if (simFileMetaEntries.ContainsKey("SUBTITLETRANSLIT"))
            {
            }

            // Sets the transliterated artist of the song, used when ShowNativeLanguage = 0.
            if (simFileMetaEntries.ContainsKey("ARTISTTRANSLIT"))
            {
            }

            // Sets the genre of the song.
            if (simFileMetaEntries.ContainsKey("GENRE"))
            {
                stepFile.Genre = simFileMetaEntries["GENRE"];
            }

            // Define's the simfile's origin (author or pack/mix).
            if (simFileMetaEntries.ContainsKey("CREDIT"))
            {
                stepFile.Credit = simFileMetaEntries["CREDIT"];
            }

            // Sets the path to the banner image for the song. Banner images are typically rectangular, with common sizes being 256x80(DDR), 418x164(ITG), and 512x160(2x DDR).
            if (simFileMetaEntries.ContainsKey("BANNER"))
            {
            }

            // Sets the path to the background image for the song. Background images are typically 640x480 or greater in resolution.
            if (simFileMetaEntries.ContainsKey("BACKGROUND"))
            {
            }

            // Sets the path to the lyrics file to use. (todo: explain.lrc format ?)
            if (simFileMetaEntries.ContainsKey("LYRICSPATH"))
            {
            }

            // Sets the path to the CD Title, a small image meant to show the origin of the song.The recommended size is around 64x48, though a number of people ignore this and make big stupid ones for some dumb reason.
            if (simFileMetaEntries.ContainsKey("CDTITLE"))
            {
            }

            // Sets the path to the music file for this song.
            if (simFileMetaEntries.ContainsKey("MUSIC"))
            {
            }

            // Sets the offset between the beginning of the song and the beginning of the notes.
            if (simFileMetaEntries.ContainsKey("OFFSET"))
            {
                stepFile.Offset = simFileMetaEntries["OFFSET"];
            }

            // Sets the BPMs for this song. BPMS are defined in the format Beat=BPM, with each value separated by a comma.
            // BPM: Beats per minute, or a measure of how fast the song is.
            if (simFileMetaEntries.ContainsKey("BPMS"))
            {
                stepFile.BPMs = this.ReadTimings(simFileMetaEntries["BPMS"]);
            }

            // Sets the stops for this song. Stops are defined in the format Beat=Seconds, with each value separated by a comma.
            // Stop: A pause in the chart that lasts a certain number of milliseconds.
            if (simFileMetaEntries.ContainsKey("STOPS"))
            {
                stepFile.Stops = this.ReadTimings(simFileMetaEntries["STOPS"]);
            }

            // Sets the start time of the song sample used on ScreenSelectMusic.
            if (simFileMetaEntries.ContainsKey("SAMPLESTART"))
            {
                stepFile.SampleStart = simFileMetaEntries["SAMPLESTART"];
            }

            // Sets the length of the song sample used on ScreenSelectMusic.
            if (simFileMetaEntries.ContainsKey("SAMPLELENGTH"))
            {
            }

            // This can be used to override the BPM shown on ScreenSelectMusic.This tag supports three types of values:
            // A number by itself(e.g. #DISPLAYBPM:180;) will show a static BPM.
            // Two numbers in a range(e.g. #DISPLAYBPM:90-270;) will show a BPM that changes between two values.
            // An asterisk(#DISPLAYBPM:*;) will show a BPM that randomly changes.
            if (simFileMetaEntries.ContainsKey("DISPLAYBPM"))
            {
            }

            // Determines if the song is selectable under normal conditions.
            // Valid values are YES and NO.
            if (simFileMetaEntries.ContainsKey("SELECTABLE"))
            {
            }

            // Defines the background changes for this song.
            // The format for each change is as follows: Beat = BGAnim =? float =? int =? int =? int.
            if (simFileMetaEntries.ContainsKey("BGCHANGES"))
            {
            }

            // Defines the foreground changes for this song.
            // Format is the same as #BGCHANGES.
            if (simFileMetaEntries.ContainsKey("FGCHANGES"))
            {
            }
        }
        static void Main(string[] args)
        {
            // http://patorjk.com/software/taag/#p=testall&f=Graffiti&t=Step%20Writer%20
            Console.WriteLine(@"               
   _________________    _      __    _ __         
  / __/_  __/ __/ _ \  | | /| / /___(_) /____ ____
 _\ \  / / / _// ___/  | |/ |/ / __/ / __/ -_) __/
/___/ /_/ /___/_/      |__/|__/_/ /_/\__/\__/_/   

            ");

            Console.WriteLine(
                "Write simple geometry data into STEP AP214 (ISO-10303) file format.\n"
                + "version: " + typeof(StepFile).Assembly.GetName().Version + " [pre-release] \n"
                );

            const string FILEPATH = @"C:\Users\me\Documents\local\file.step";

            Console.WriteLine("Want to write the STEP file with sample content to:\n" + FILEPATH + " ?");
            Console.ReadKey();
            Console.WriteLine("...working...");

            StepFile stepFile = new StepFile(FILEPATH, "RootAssembly");

            stepFile.AddBox(
                name: "origin",
                position: new Vector3(0, 0, 0),
                dimension: new Vector3(10, 10, 10),
                rotation: new Vector3(0, 0, 0),
                color: Color.Red,
                parentId: 0
                );

            // let's build a sample workstation

            int workstationId = stepFile.AddGroup(
                name: "workstation",
                position: new Vector3(0, 0, 0),
                rotation: new Vector3(0, 0, 0),
                parentId: 0
                );

            int tableId = stepFile.AddGroup(
                name: "table",
                position: new Vector3(0, 0, 0),
                rotation: new Vector3(0, 0, 0),
                parentId: workstationId
                );

            int stuffId = stepFile.AddGroup(
                name: "stuff",
                position: new Vector3(0, 0, 630),
                rotation: new Vector3(0, 0, 0),
                parentId: workstationId
                );

            int foundationId = stepFile.AddGroup(
                name: "foundation",
                position: new Vector3(0, 0, 0),
                rotation: new Vector3(0, 0, 0),
                parentId: tableId
                );

            stepFile.AddBox(
                name: "leg1",
                position: new Vector3(-750, -250, 300),
                dimension: new Vector3(100, 100, 600),
                rotation: new Vector3(0, 0, 0),
                color: Color.Green,
                parentId: foundationId
                );

            stepFile.AddBox(
                name: "leg2",
                position: new Vector3(750, -250, 300),
                dimension: new Vector3(100, 100, 600),
                rotation: new Vector3(0, 0, 0),
                color: Color.Green,
                parentId: foundationId
                );

            stepFile.AddBox(
                name: "leg3",
                position: new Vector3(-750, 250, 300),
                dimension: new Vector3(100, 100, 600),
                rotation: new Vector3(0, 0, 0),
                color: Color.Green,
                parentId: foundationId
                );

            stepFile.AddBox(
                name: "leg4",
                position: new Vector3(750, 250, 300),
                dimension: new Vector3(100, 100, 600),
                rotation: new Vector3(0, 0, 0),
                color: Color.Green,
                parentId: foundationId
                );

            stepFile.AddBox(
                name: "tabletop",
                position: new Vector3(0, 0, 615),
                dimension: new Vector3(1600, 600, 30),
                rotation: new Vector3(0, 0, 0),
                color: Color.Blue,
                parentId: foundationId
                );

            int drawerId = stepFile.AddGroup(
                name: "drawer",
                position: new Vector3(-550, 0, 450),
                rotation: new Vector3(0, 0, 0),
                parentId: tableId
                );

            stepFile.AddBox(
                name: "walls",
                position: new Vector3(0, 50, 0),
                dimension: new Vector3(300, 500, 300),
                rotation: new Vector3(0, 0, 0),
                color: Color.Yellow,
                parentId: drawerId
                );

            stepFile.AddBox(
                name: "knob1",
                position: new Vector3(0, -225, 50),
                dimension: new Vector3(100, 50, 35),
                rotation: new Vector3(0, 0, 0),
                color: Color.Black,
                parentId: drawerId
                );

            stepFile.AddBox(
                name: "knob2",
                position: new Vector3(0, -225, -60),
                dimension: new Vector3(100, 50, 35),
                rotation: new Vector3(0, 0, 0),
                color: Color.Black,
                parentId: drawerId
                );

            stepFile.AddBox(
                name: "book1",
                position: new Vector3(540, 35, 30),
                dimension: new Vector3(250, 360, 60),
                rotation: new Vector3(0, 0, -35),
                color: Color.White,
                parentId: stuffId
                );

            stepFile.AddBox(
                name: "book2",
                position: new Vector3(540, 35, 90),
                dimension: new Vector3(250, 360, 60),
                rotation: new Vector3(0, 0, -38),
                color: Color.Yellow,
                parentId: stuffId
                );

            int monitorId = stepFile.AddGroup(
                name: "monitor",
                position: new Vector3(0, 170, 0),
                rotation: new Vector3(0, 0, -4),
                parentId: stuffId
                );

            stepFile.AddBox(
                name: "socket",
                position: new Vector3(0, 0, 20),
                dimension: new Vector3(250, 150, 40),
                rotation: new Vector3(0, 0, 0),
                color: Color.Black,
                parentId: monitorId
                );

            stepFile.AddBox(
                name: "arm",
                position: new Vector3(0, 0, 190),
                dimension: new Vector3(100, 30, 300),
                rotation: new Vector3(0, 0, 0),
                color: Color.Black,
                parentId: monitorId
                );

            stepFile.AddBox(
                name: "display",
                position: new Vector3(0, -10, 340),
                dimension: new Vector3(600, 20, 338),
                rotation: new Vector3(0, 0, 0),
                color: Color.Black,
                parentId: monitorId
                );

            stepFile.AddBox(
                name: "keyboard",
                position: new Vector3(-110, -75, 0),
                dimension: new Vector3(560, 185, 40),
                rotation: new Vector3(0, 0, -6),
                color: Color.Red,
                parentId: stuffId
                );

            bool result = stepFile.WriteFile();

            // alternatively you can use: byte[] data = stepFile.GetStepData();

            if (result)
            {
                Console.WriteLine("Success.");
            }
            else
            {
                Console.WriteLine("Failure.");
            }

            Console.ReadKey();
        }
        private void ParseNotes(List <string> simNoteEntries, StepFile stepFile)
        {
            const int metaEntries = 5;

            foreach (string simNoteEntry in simNoteEntries)
            {
                Difficulty stepFileDifficulty = new Difficulty(stepFile);

                ChartType chartType    = ChartType.None;
                string    description  = String.Empty;
                string    difficulty   = String.Empty;
                int       numericMeter = 0;
                string    grooveRadar;

                using (StringReader stringReader = new StringReader(simNoteEntry))
                {
                    int symbol;

                    // Parse notes tags
                    int    index = 0;
                    string value = String.Empty;

                    while ((symbol = stringReader.Read()) >= 0 && index < metaEntries)
                    {
                        // The Notes tag contains the following information:
                        //
                        // [0] Chart type (e.g.dance - single)
                        // [1] Description / author
                        // [2] Difficulty(one of Beginner, Easy, Medium, Hard, Challenge, Edit)
                        // [3] Numerical meter
                        // [4] Groove radar values, generated by the program
                        //
                        // The first five values are postfixed with a colon.
                        // Groove radar values are separated with commas.

                        if (symbol != COLON)
                        {
                            if (symbol != LINE_FEED &&
                                symbol != CARRIAGE_RETURN &&
                                symbol != SPACE)
                            {
                                value += (char)symbol;
                            }
                        }
                        else
                        {
                            switch (index)
                            {
                            case 0:
                                if (value == "dance-single")
                                {
                                    chartType = ChartType.FourKey;
                                }
                                else if (value == "pump-single")
                                {
                                    chartType = ChartType.FiveKey;
                                }
                                else if (value == "dance-solo")
                                {
                                    chartType = ChartType.SixKey;
                                }
                                else if (value == "kb7-single")
                                {
                                    chartType = ChartType.SevenKey;
                                }
                                else if (value == "dance-double")
                                {
                                    chartType = ChartType.EightKey;
                                }
                                else if (value == "pump-double")
                                {
                                    chartType = ChartType.TenKey;
                                }
                                break;

                            case 1: description = value; break;

                            case 2: difficulty = value; break;

                            case 3: int.TryParse(value, out numericMeter); break;

                            case 4: grooveRadar = value; break;
                            }

                            value = string.Empty;
                            index++;
                        }
                    }

                    if (chartType != ChartType.None)
                    {
                        stepFileDifficulty.ChartType = chartType;
                        stepFileDifficulty.Level     = numericMeter;

                        // Parse notes
                        int slashCount = 0;
                        value = string.Empty;

                        while ((symbol = stringReader.Read()) >= 0)
                        {
                            if (symbol == SLASH)
                            {
                                slashCount++;
                                continue;
                            }

                            if (slashCount > 1)
                            {
                                // comment, eat until \r or \n is encountered
                                if (symbol != LINE_FEED || symbol != CARRIAGE_RETURN)
                                {
                                    continue;
                                }

                                slashCount = 0;
                            }

                            if (symbol != LINE_FEED &&
                                symbol != CARRIAGE_RETURN &&
                                symbol != SPACE &&
                                symbol != TABULATOR)
                            {
                                value += (char)symbol;
                            }
                        }

                        string[] measurements    = value.Split(',');
                        int      measureRowIndex = 0;

                        foreach (string measureRow in measurements)
                        {
                            // Note data itself is a bit more complex;
                            // there's one character for every possible playable column in a chart type.
                            // Note types (e.g. 4th, 8th, etc.) are determined by how many rows exist before the comma (which separates measures).

                            int notesPerLine = (int)chartType;
                            int lineCount    = measureRow.Length / notesPerLine;

                            Measure measure = new Measure(stepFile);
                            measure.Index = measureRowIndex;

                            for (int currentLineCount = 0; currentLineCount < lineCount; currentLineCount++)
                            {
                                Line line = new Line(stepFile);
                                line.Index = currentLineCount;

                                int noteStartIndex = currentLineCount * notesPerLine;

                                for (int currentNoteInLine = 0; currentNoteInLine < notesPerLine; currentNoteInLine++)
                                {
                                    Step step = new Step(stepFile);
                                    step.Index = currentNoteInLine;

                                    int currentNoteIndex = noteStartIndex + currentNoteInLine;

                                    switch (measureRow[currentNoteIndex])
                                    {
                                    // Note Values
                                    // These are the standard note values:
                                    //
                                    // 0 – No note
                                    // 1 – Normal note
                                    // 2 – Hold head
                                    // 3 – Hold / Roll tail
                                    // 4 – Roll head
                                    // M – Mine
                                    // Later versions of StepMania accept other note values which may not work in older versions:
                                    //
                                    // K – Automatic keysound
                                    // L – Lift note
                                    // F – Fake note
                                    // Non - Standard Tags
                                    // You might run into some .sm files with some non - standard tags.Though these aren't supported by StepMania, they're good to know.

                                    case '0': step.StepType = StepType.None; break;

                                    case '1': step.StepType = StepType.Normal; break;

                                    case '2': step.StepType = StepType.HoldStart; break;

                                    case '3': step.StepType = StepType.HoldEnd; break;

                                    case '4': step.StepType = StepType.RollStart; break;

                                    case 'M': step.StepType = StepType.Mine; break;

                                    case 'K': break;

                                    case 'L': break;

                                    case 'F': break;
                                    }
                                    line.Steps.Add(step);
                                }
                                measure.Lines.Add(line);
                            }
                            stepFileDifficulty.Measures.Add(measure);
                            measureRowIndex++;
                        }
                    }
                    else
                    {
                        // invalid chart type
                    }
                }
                stepFile.Difficulties.Add(stepFileDifficulty);
            }
        }
        private void WriteNotes(StepFile stepFile, BinaryWriter binaryWriter)
        {
            foreach (Difficulty difficulty in stepFile.Difficulties)
            {
                this.WriteString("#NOTES:", binaryWriter);
                this.WriteNewLine(binaryWriter);

                // ChartType
                string chartType = string.Empty;
                switch (difficulty.ChartType)
                {
                case ChartType.FourKey: chartType = "dance-single"; break;

                case ChartType.FiveKey: chartType = "pump-single"; break;

                case ChartType.SixKey: chartType = "dance-solo"; break;

                case ChartType.SevenKey: chartType = "kb7-single"; break;

                case ChartType.EightKey: chartType = "dance-double"; break;

                case ChartType.TenKey: chartType = "pump-double"; break;
                }
                this.WriteString(string.Format("{0}:", chartType), binaryWriter);
                this.WriteNewLine(binaryWriter);

                // Description
                this.WriteString(string.Format("{0}:", "description"), binaryWriter);
                this.WriteNewLine(binaryWriter);

                // Difficulty (string)
                this.WriteString(string.Format("{0}:", ""), binaryWriter);
                this.WriteNewLine(binaryWriter);

                // Numeric Difficulty (int)
                this.WriteString(string.Format("{0}:", difficulty.Level), binaryWriter);
                this.WriteNewLine(binaryWriter);

                //Groove Radar (CSV-List)
                this.WriteString(string.Format("{0}:", ""), binaryWriter);
                this.WriteNewLine(binaryWriter);

                int currentMeasureIndex = 0;

                difficulty.Measures.Sort((x, y) => y.Index.CompareTo(x.Index));
                foreach (Measure measure in difficulty.Measures)
                {
                    measure.Lines.Sort((x, y) => y.Index.CompareTo(x.Index));
                    foreach (Line line in measure.Lines)
                    {
                        line.Steps.Sort((x, y) => y.Index.CompareTo(x.Index));
                        foreach (Step step in line.Steps)
                        {
                            char stepType = '0';
                            switch (step.StepType)
                            {
                            case StepType.Normal: stepType = '1'; break;

                            case StepType.HoldStart: stepType = '2'; break;

                            case StepType.HoldEnd: stepType = '3'; break;

                            case StepType.RollStart: stepType = '4'; break;

                            case StepType.Mine: stepType = 'M'; break;

                            default:
                            case StepType.None: stepType = '0'; break;
                            }
                            binaryWriter.Write((byte)stepType);
                        }
                        this.WriteNewLine(binaryWriter);
                    }

                    currentMeasureIndex++;

                    if (difficulty.Measures.Count == currentMeasureIndex)
                    {
                        binaryWriter.Write((byte)';');
                    }
                    else
                    {
                        binaryWriter.Write((byte)',');
                    }

                    this.WriteNewLine(binaryWriter);
                }
            }
        }
Exemple #28
0
 public Step(StepFile stepFile)
 {
     this.StepFile = stepFile;
     this.Index    = 0;
     this.StepType = StepType.None;
 }
Exemple #29
0
        private void AssertFileContains(StepFile file, string expected, bool inlineReferences = false)
        {
            var actual = file.GetContentsAsString(inlineReferences);

            Assert.Contains(expected, actual.Trim());
        }
Exemple #30
0
        public iso_10303 Bind(StepFile step)
        {
            if (step == null)
            {
                throw new ArgumentNullException("step");
            }
            if (step.Data == null)
            {
                throw new ArgumentNullException("step.Data");
            }
            if (step.Header == null)
            {
                throw new ArgumentNullException("step.Header");
            }

            iso_10303 iso10303 = new iso_10303();

            //TODO fill in meta data from STEP header
            iso10303.iso_10303_28_header = new iso_10303_28_header();
            foreach (StepDataObject sdo in step.Header)
            {
                logger.Debug("Found header object : " + sdo.ObjectName);
                if (sdo.ObjectName == "FILE_NAME")
                {
                    bindFileName(sdo, iso10303.iso_10303_28_header);
                }
            }

            iso10303.uos = new uos1();
            IDictionary <int, Entity> entities = new SortedDictionary <int, Entity>();

            //try and instantiate a type for each STEP entity
            //and fill its properties
            foreach (KeyValuePair <int, StepDataObject> kvp in step.Data)
            {
                if (kvp.Value == null)
                {
                    continue;
                }

                Object o = this.bindObject(kvp.Key, kvp.Value);

                //TODO check that instance type is derived from Entity.
                Entity e = o as Entity;

                logger.Debug("Adding a deserialized item.  Item Id : " + kvp.Key);

                entities.Add(kvp.Key, e);
            }
            logger.Info(String.Format(CultureInfo.InvariantCulture, "Deserialized {0} entities", entities.Count));

            LinkReferences(entities);

            Entity[] items = new Entity[entities.Count];
            entities.Values.CopyTo(items, 0);
            ((uos1)iso10303.uos).Items = items;

            //clear object links so there's no issues next time this method is run
            this._objectLinks = new List <StepEntityReference>();

            return(iso10303);
        }
Exemple #31
0
 public Step(StepFile stepFile)
 {
     this.StepFile = stepFile;
     this.Index = 0;
     this.StepType = StepType.None;
 }