Jump to content
Sign in to follow this  
FlyingsCool

Case statement and general confusion

Recommended Posts

Hi,I'm trying to make an lcd rpm gauge that adds a bar to a circle of bars as the rpm goes up and I'm looking for ideas on how to accomplish it.http://forums.avsim.net/user_files/175580.jpgI'm just getting into gauge programming. 20 years ago, I was a pretty efficient fortran programmer, but it appears that the procedural programming I was used to is rather different than gauge programming.My first thought is to have a separate image for each state, i.e. 1 image each for 0 bars, 1 bar, 2 bars, 3 bars, ... 20 bars. Then use a case statement (or set of case statements) based on the current value of the percent of the available rpm range (i.e. 0 - 110% max rpm).But all this variable stuff and syntax has my head spinning.I found a case statement from another gauge and I've been reading the SDK, but I can't make heads or tails of how to apply it to my situation.First, here's something that I sort of understand: 195.000,33.2500.000True???X,gt 0, lt 5??? True... How do I use Expression and ExpressionResult to do what I am looking for. After case 0, the other cases are between 0 and 5, 5 and 10, etc.. How do I put this in ExpressionResult? Do I create a local variable L:ExpRes = %RPM in the Expression script and then create an expression 0 < L:ExpRes < 5, and so on for each expression result? Any hints on syntax?Since there is no rotation involved and each graphic is static and just replaces the next, it seems like I should be able to code a macro which, given the max number of bars to be drawn, the min/max value that the min/max graphic is drawn for, and a prefix for the filename, should be able to create the case sets automatically. Graphic filenames would be somthing like L00.bmp, L01.bmp, L02.bmp... for a large circle, S00.bmp, S01.bmp, S02.bmp, ... for a small circle, V00.bmp, V01.bmp, V02.bmp,... for a vertical bar graph (a series of dashes).Here's an example I found that accomplishes a case statement in a more compact form, but, again, I can't make heads or tails of it. The SDK says syntax is very strict, but I can't seem to find a good reference on how to write the syntax for anything. There are various pieces in the examples here and there, but I don't understand what some of the symbols are there for:%((@1))%{case}%{:1}%((@2,degrees) 45 / near 4 %)%{case}%{:0}1%{:1}2%{:2}3%{:3}4%{end}%{:2}5%{:3}6%{:4}7%{:5}8%{end}How are the % symbols being used in the case statement? I know that whatever is between % symbols should be evaluated, but they aren't in pairs surrounding the different case evaluations. And how are the case statements evaluated? Does it mean if expression = 0 use 1, if expression = 1 use 2, and so on? Or is it if expression gt 0 & lt 1 use 1, if expression gt 1 & lt 2, use 2, etc.? And how are the {end} statements being used here? I don't see any conditional concept like an else or something?Can anybody think of a better way to accomplish this? I haven't been able to find any xml gauges that have even close to this functionality as far as I can tell.I'm going to keep reading the SDK and searching here.Thanks!Thomas[a href=http://www.flyingscool.com] http://www.flyingscool.com/images/Signature.jpg [/a]I like using VC's :-)N15802 KASH '73 Piper Cherokee Challenger 180


Tom Perry

 

Signature.jpg

Share this post


Link to post
Share on other sites

Ok, I found the inline case statement example and I understand the syntax a little better, but I still don't get how to apply it, nor do I understand what the {end} statements are used for.I guess based on how the case statement is explained, if I multiply the %RPM by 10, then it will evaluate to numbers between 0 and 1, 1 and 2, etc., but I still don't understand what to put into ExpressionResult for each case.Thomas[a href=http://www.flyingscool.com] http://www.flyingscool.com/images/Signature.jpg [/a]I like using VC's :-)N15802 KASH '73 Piper Cherokee Challenger 180


Tom Perry

 

Signature.jpg

Share this post


Link to post
Share on other sites

Hi Thomas,What you need to do is a simple task for anyone that has a bit of XML knowledge, so I suggest you first go to http://www.fs2x.com/Tutorials.htmand read the wonderful information posted there. After then, I guess you'll understand structures, which are different to {case} in strings, and learn how to rotate a single bitmap, which would be the procedure to code in your example.Tom

Share this post


Link to post
Share on other sites

Hi Tom,Thanks for the link, I will definately read it.I didn't think that rotation would do the trick. I know how to create a rotating needle. But, in this case, as the RPM increases, bars are added in a circular pattern (as shown in the image), so, unless FSX knows how to leave a ghost behind as the needle rotates, I didn't think this would work, and I haven't seen any similar functionality in the SDK. Plus, each bar is in a fixed location, they don't rotate around, they just appear when a limit is reached. So, my original idea was to show a different graphic for each 5% rise (rather than piling up a whole bunch of graphics, one for each bar). The first graphic has one bar, then that's replaced by a graphic with 2 bars, and so on. But now I'm thinking, given my knowledge and desire to do as little coding as possible, I think using a pie object as a mask might work more easily; as now I can just use a function to calculate the angle, rather than having to pass variables around, which I'm not comfortable with yet, and I won't have to create a whole bunch of graphic images.Thomas[a href=http://www.flyingscool.com] http://www.flyingscool.com/images/Signature.jpg [/a]I like using VC's :-)N15802 KASH '73 Piper Cherokee Challenger 180


Tom Perry

 

Signature.jpg

Share this post


Link to post
Share on other sites

Hi Thomas,Yeah, rotation would do the trick, believe me :-)You need to use a bitmap similar to the one in your first post (but SQUARED) and another that would do the masking action, both rotating in inverse way, -sort of.Anyway, making single bitmaps for every bar would work for sure.Tom

Share this post


Link to post
Share on other sites

Or, you could define an object "lozenge" by listing the vertex points, then simply rotate it.Here is an example in C++ perhaps you can "translate" it to XML:/* Engine Power Display */ for(int u = 0; u < (int)(0.2 * throttle_pos); u++) { graphics.TranslateTransform(127 * dx, 132 * dy); graphics.RotateTransform(u * 11); /* Define the Large Arrow structure */ Point PWR_1(-38 * dx, 33 * dy); Point PWR_2(-34 * dx, 37 * dy); Point PWR_3(-66 * dx, 75 * dy); Point PWR_4(-76 * dx, 75 * dy); Point PWR_5(-76 * dx, 65 * dy); Point PWR_blade[6] = {PWR_1, PWR_2, PWR_3, PWR_4, PWR_5, PWR_1}; graphics.FillPolygon(&blackBrush, PWR_blade, 6); graphics.ResetTransform(); } PointF pointPower(108*dx, 148*dy); swprintf(buf_wch, L"%3.0f", throttle_pos); graphics.DrawString(buf_wch, -1, &LargeNumbers, pointPower, &blackBrush);


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

So I think what you are saying for this idea is; I could make a macro of a 6 sided polygon. Then for each case I could display (or turn off) a new polygon at a specific rotation value. I like this one because I assume it handles the antialiasing of the polygon at each rotation?, which is great, because I'm an awful painter so getting each poly to look smooth is not easy for me.And I believe I could create a couple of macros to ease the programming.Thomas[a href=http://www.flyingscool.com] http://www.flyingscool.com/images/Signature.jpg [/a]I like using VC's :-)N15802 KASH '73 Piper Cherokee Challenger 180


Tom Perry

 

Signature.jpg

Share this post


Link to post
Share on other sites

I read through the above tutorials, but it doesn't explain how a case statement is evaluated. But after some testing, it appears that case statement is not what I am looking for. It appears that ExpressionResult is only a float, so I can't put an expression in it, which in turn means a case object in a Select object only evaluates when an expression result is Equal to ExpressionResult. What I am look for is if(x=0) do this, if (0http://www.flyingscool.com/images/Signature.jpg [/a]I like using VC's :-)N15802 KASH '73 Piper Cherokee Challenger 180


Tom Perry

 

Signature.jpg

Share this post


Link to post
Share on other sites

Eureka, OR what I should be doing with my expression is having it round down to particular values when they are within the ranges I want. I get it.Sorry for my thickheadedness.Thomas[a href=http://www.flyingscool.com] http://www.flyingscool.com/images/Signature.jpg [/a]I like using VC's :-)N15802 KASH '73 Piper Cherokee Challenger 180


Tom Perry

 

Signature.jpg

Share this post


Link to post
Share on other sites

Ok, I've got the case object method working now using:Where X = GaugeValMax/NumBarsNow I have to figure out an efficient way to make a macro out of the Select object or some portion of it. I'm a little stumped on how to replace an object with a macro. But I'll work on that later.Thanks!Thomas[a href=http://www.flyingscool.com] http://www.flyingscool.com/images/Signature.jpg [/a]I like using VC's :-)N15802 KASH '73 Piper Cherokee Challenger 180


Tom Perry

 

Signature.jpg

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...