My TGM geometry tool

Discussion in 'Third Party Content' started by jtbo, Nov 14, 2012.

  1. jtbo

    jtbo Registered

    Joined:
    Jan 12, 2012
    Messages:
    1,668
    Likes Received:
    48
    Update at bottom of post, now it is possible to test and contribute to project.

    Here is small preview from one of my projects, currently bit over 60 hours has gone to it as I really had no skills in programming for this kind of project so every thing in it has been wall to be climbed, however while doing it I have learned already great deal about programming which was actually main purpose why I did start such project.

    This is done in Visual C# 2008 express.

    v0.2a win32 binary setup download with Save function (zip, 216kb):
    https://github.com/downloads/JTbo/JTbo_Tools/TGM_editor_0.2alpha.zip
    Extract to temp folder, run setup.exe.

    v0.2a source download (zip, 296kb):
    https://github.com/downloads/JTbo/JTbo_Tools/TgmEditor_v0.2a.zip


    View attachment 4683

    It is quite ugly at the moment because I have had not much plans for UI as of yet. (also my color scheme in windows is not very pretty, but it saves my old eyes) However I would like to create dots representing nodes to left side of boxes. Those boxes are actually generated by the code, so if you have more nodes there is more of them and if you have less nodes there are less of them, currently having more than 32 nodes will probably crash the tool or do some weird things, there is not much of fail safes or anything robust in it right now.

    This is roughly how it works as of now.
    From open button one can open tgm file and program reads the file, parses values to array and creates text boxes with values in them. Also program outputs read lines to bottom box.

    Catch here is that only values from node 0 to node containing center of tire are read, rest are then generated. Reason for this is that I have only symmetric tires to work with and I certainly don't like typing same values over and over again, so program calculates those.

    Next I will do code for generate button, I have planned it so that it should read text boxes and generate other side of tire, then output everything to bottom text box, so I can actually use tool for something and copy paste those lines to tgm file.

    There is also save button, it does nothing at the moment, but I want it to be able to write lines into tgm file, however it is not yet quite clear for me how to achieve this. Currently I plan to test same parsing code as when reading to find location and write line there, but I'm not too sure if that is going to work at least easily.

    I have very little experience and 0 education in coding, I just do tutorials what I find from net, try to code something and when not be able to figure out what to do I search from the net, slowly I learn then.

    When I get it to somehow working stage, I plan to put it up to github or similar as it is going to be open source as that is my way, then anyone is of course welcome to improve it.

    For those using Notepad++ my regex parameters might be useful or then not, I have not had time to test how well they would work in Notepad++.

    To find lines to read I use this: @"Geometry=\(*"

    1st param @"\-?\d{1}\.?[0-9]*"
    2nd param @"\,\-\d{1}\.[0-9]*\,"
    3rd param @"\,\d{1}\.[0-9]*\)"

    Then I clean up 2nd param with "\\,", ""

    And cleaning up 3rd param I use two as I could not figure out how to get one to clean both comma and bracket
    "\\)", ""

    "\\,", ""
    Cleaning up in C# is possible Regex.Replace.

    Here is some link to Notepad++ RegEx stuff that I have not read, but which might be useful for those wanting to know more about that.
    http://markantoniou.blogspot.fi/2008/06/notepad-how-to-use-regular-expressions.html

    Might not be the most useful tool of course, but for me at least nice byproduct from learning programming :)

    INSTRUCTIONS and stuff you need to know:
     
    Last edited by a moderator: Nov 17, 2012
  2. Abriel Nei

    Abriel Nei Registered

    Joined:
    Aug 7, 2012
    Messages:
    714
    Likes Received:
    37
    If you need any help with programming I offer my help (if you need some tips on how to or even to write some code) :)
     
  3. jtbo

    jtbo Registered

    Joined:
    Jan 12, 2012
    Messages:
    1,668
    Likes Received:
    48
    Thanks from offer, I'm sure that there will be that big wall at some point when trying to get saving to work :)

    One issue I forgot to mention is that infamous comma vs dot problem.

    As it is of now, one has to use dot as decimal separator, because .NET relies on culture in there and if your system is set to have comma as decimal separator it can't read properly TGM file which uses dot as decimal separator.

    I did research on this and all solutions I have currently found would be bit much of work to solve and as I'm using dot as decimal separator in my system anyway, it does not bother me too much.

    One solution might be to rewrite tgm file replacing dot with comma do edits and convert dot to comma again after writing file, but that would be rather ugly solution and probably would cause more issues than it cures, however writing that would be more simple than what I have found so far how others have came around of that issue.

    Compared to effort needed to overcome such small thing, changing system delimiter is just so much easier, so I have not really put much of time on that one.

    Reminds me again from performance counters issues that I once had, MS in it's great wisdom has localized .NET library and performance counters also, so source that works in another machine does not work on another as memory is muisti or something like that in performance counters.

    Reason I'm not too fond of localized versions, like to stick with plain old english and dot over comma in my system settings :)
     
  4. Abriel Nei

    Abriel Nei Registered

    Joined:
    Aug 7, 2012
    Messages:
    714
    Likes Received:
    37
    You can specify the localization when you parse decimal. In this case delimiter is always the same independent of the users culture so you should use InvariantCulture.
    Example:
    String temp = "123.45";
    Decimal value = Decimal.Parse(temp, System.Globalization.CultureInfo.InvariantCulture);
     
    1 person likes this.
  5. jtbo

    jtbo Registered

    Joined:
    Jan 12, 2012
    Messages:
    1,668
    Likes Received:
    48
    Thanks, that works great :)

    I had come across of InvariantCulture before, but what I could not find for it was Globalization.
     
  6. Mario Morais

    Mario Morais Registered

    Joined:
    Oct 26, 2010
    Messages:
    1,465
    Likes Received:
    169
    This tool is to Generate random tyres?
     
  7. jtbo

    jtbo Registered

    Joined:
    Jan 12, 2012
    Messages:
    1,668
    Likes Received:
    48
    Not random, well, one can make randoms if one like, but mostly to help creating geometry entries that are easily possible to calculate instead of manually inputting every value.

    I hope to have eventually tire size based generation in place, so one would just need to open tgm, set tire size and save TGM, but I haven't still quite figured out best methods to achieve that.

    Generate button misses down arrow as I could not find out how to get that made, but it should generate new values to bottom box based on inputs that are made to those upper boxes. All it does is put Geometry=(v1,v2,v3) for each line, instead of just having v1,v2,v3.

    That is actually still a plan, need to write code for that, but mostly I can use what code I already have, so should not be too difficult, but I never know before hand what challenges lies ahead. Anyway when that is done, I think that I can put out a preview version as it can then be used for something, even still being alpha.
     
  8. jtbo

    jtbo Registered

    Joined:
    Jan 12, 2012
    Messages:
    1,668
    Likes Received:
    48
    Ok, I got it to work somehow and I tested with couple of tires and seems to be working, so it can be used for something, however you should remember that I'm just learning programming and this is ALPHA version, so there can be gremlins there, beware!

    What I would need to do is clean up source, as it is as of now, nobody probably can't make any sense out from it, also old code is commented out, but there are really no any comments, so before I start to work with save functionality I need to clean up source a bit. Also I probably do many things in ineffective way in source, there probably is better ways to accomplish things, so that too is one thing to do.

    Then there is general coding, how neatly it is written, which is where I need to do a lot of work. Also I haven't figure out about functions and classes yet, but I imagine that running everything inside button click event is not way to go, I would imagine there would be function or class for program and I would call it from button click event, but it is something I still need to study, I barely can get it to work with low skills, but even so it might help a bit with editing.

    This is project's page at Git hub:
    https://github.com/JTbo/JTbo_Tools/tree/tgm_editor

    This is address to repo, which you can pull with tortoise git, I did set up it as tgm_editor branch, who knows, maybe I make tool suite some day, eh?:
    https://github.com/JTbo/JTbo_Tools.git

    HOW TO USE:
    It installs into JTbo Tools -> TGM editor

    When opened, hit enter, browse copy of TGM file you wish to edit and hit open.

    Edit values, each line is one node, from node 0 to node that is at center of tire, format is same as in TGM file, width, height, thickness.

    When typing is complete, hit Generate button and all Geometry lines are generated to bottom box, where from you can copy and paste each line to your TGM file.

    I believe that Notepad++ could be used find and replace all values at once. One day there will be save function of course.

    So this mainly saves from typing as for now.

    BEWARE:
    Don't attempt to use with TGM that has more nodes than what Clio tires have, there is bit of space issues on my screen at least.

    Screen height, you probably don't want to use anything less than 1080 pixels, program is 715; 898 pixels in size, so having less than 900 pixels tall screen is causing some of the program being outside of the screen.

    Something I would like to solve in future, when I get UI planned out. It is just a rough tool for my usage at the moment, if is any use for you, good, but at this stage it is not intended to be pretty or anything for wide usage, at this stage I put it up as open source and perhaps some can find it worth his time to improve it.

    I like GNU/GPL License, make your own version, mention original creator and share the source, so that is what I may go with at some point.
     
  9. Abriel Nei

    Abriel Nei Registered

    Joined:
    Aug 7, 2012
    Messages:
    714
    Likes Received:
    37
    About classes and functions. Generally it is nice practice to create a class that holds all functions to work with specific thing. In your case TGM file. So for example create a class called TgmManager or something.
    Then you split your code into functions, for example a function to read tgm file and returns all text.
    public static string ReadTgm(string fullFileName)
    {
    ...
    returns alltext;
    }

    and another to save
    public static void SaveTgm(string fullcontent, string fullOutputFilename)
    {
    ...
    }

    Then you call the functions
    string content = TgmManager.ReadTgm(filename);

    etc.
     
  10. jtbo

    jtbo Registered

    Joined:
    Jan 12, 2012
    Messages:
    1,668
    Likes Received:
    48
    Thanks, it surely is something I need to do, I'm finding that on that area I need to still learn to think bit differently, more like programmer, my logic and language's logic seem not always to be agreeing how to achieve something :p

    So first I need to do few practice programs with classes and functions, which should help me see how to achieve what I want in this tool.
     
  11. jtbo

    jtbo Registered

    Joined:
    Jan 12, 2012
    Messages:
    1,668
    Likes Received:
    48
    Of course I could not wait to make save function when I got idea of how to make it work, so there is now new version, 0.2 Alpha available that can save TGM files.

    But be careful with it, have backups up to date and operate only with copies of original tire files. Not my fault if your machine goes kaboom, I have warned you :)

    It has not all the functionalities yet in, so here is quick quide how to use.

    After opening tool, click open, select copy of TGM file you want to edit. (if you choose wrong file tool crashes)

    Make edits as you see fit, then click generate and tool writes your edits to bottom box and also generates other half of tire too. It is possible to copy values from box to TGM file manually also.

    Click save button, choose location where you want to save your NEW tgm file, write NEW name and remember .tgm extension (in future I make that automatic). If you choose existing file, tool probably crashes or makes TGM file useless, that part of tool is not yet finished, it can only create NEW files, afaik, haven't even tested overwriting yet.

    After you have saved your NEW tgm, tool writes whole TGM file into bottom text box, so you can quickly look if file looks ok, without need of opening file separately. Also tool retains generated geometry lines at top of the bottom box so that you can compare values, copy them and whatever you wish to do with them.

    Remember to close tool after that, I have attempted to make it so that you could do 2nd tires in a row, but there might be bugs as that part requires still testing, so only one tires for one tool startup is something I have seen working. This is alpha after all, only intended to give preview and offer possibility to test and perhaps even help with creation of tool, but it still may be useful.

    Download installer from here:
    https://github.com/downloads/JTbo/JTbo_Tools/TGM_editor_0.2alpha.zip
     
  12. Abriel Nei

    Abriel Nei Registered

    Joined:
    Aug 7, 2012
    Messages:
    714
    Likes Received:
    37
    About dialog:
    You can set Filter property to "*.tgm" so it will only show tgm files (same when saving - it will automatically add tgm extension if it is not specified).

    About saving:
    The second parameter when creating new StreamWriter is true/false. If true then the contents are appended, if false the contents are overwritten. In your case you should set it to false because I doubt tgm file would work ok if the contents would be appended to the end of already existing tgm file.

    Some random tips:
    When defining some variable you can use the var keyword instead specifying exact type if it is initialized in the same command (and it really should be in most cases, you should not define variables before you need them).
    Example:
    string[] results2 = new string[33];
    can be written as
    var results2 = new string[33];

    but:
    string v;
    can't be written as var v;

    Also try to define variables when and where you need them, you don't need to define them all in the class (at the top). If you define them at the top basically you reserve some memory for each of them and it is reserved if you need them or not. If you define them in some function memory is reserved only as long as the function executes and then released. Of course memory is not a concern in this case because it is only a small tool but that is a rule of making clean code.
     
  13. jtbo

    jtbo Registered

    Joined:
    Jan 12, 2012
    Messages:
    1,668
    Likes Received:
    48
    Thanks from tips, it is always nice to hear them :)

    I had problem that it did wrote everything for one line, only with append it started to write line after line, I believe reason is because I write line by line from array to file, but as I did made some changes I now would have whole file stored in array and I might be able to write that whole array to file, which might be tad more efficient.

    When I figure out those functions and classes, then I will need to place variable declarations to new place, I really would need to start with that and rewrite everything to nicer form.

    One limitation currently are those arrays of size 33 I put there, they should be sized by length of file, but that awaits bit of UI changes as space becomes quickly to issue, however I don't know how many nodes people are really using.
    That I could however read from numnodes line with RegEx, it would also make few other places much better and robust.



    Few new things in my mind currently are import and export to 3ds max so one could make easily scaling, I don't know math for two dimensional scaling of such spline shape as proportions should stay same.

    Also quick select buttons for different tire sizes, or input box, but unless I figure out scaling formulas, I think that I have to settle with presets only.

    Most of that tire geometry stuff can be automated, so for me at least it would make sense to have machine do such things.

    For me this is bit like magic to be able to actually make some program that actually does something, I am far from programmer, but when I learn to make cleaner code and get into it more, it clearly opens whole new kind of possibilities. Feeling like kid in toy store, so much of everything :p
     

Share This Page