当前位置:网站首页>[splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
[splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
2022-07-01 17:30:00 【beidou111】
principle :splishsplash Medium MVC Patterns and GenericParameter
splishsplash Have adopted the MVC Design patterns . The biggest feature of this design pattern is to separate the user interface from the back-end data calculation , It's also known as “ front end ” and “ Back end ” Separate . actually , As long as it involves GUI Or graphics program , Are almost more or less necessary MVC Design patterns .
MVC The three letters in represent Model View Controller
Model Be responsible for data calculation ,View Responsible user IO( That is, display the interface and receive user input ),Controller Be responsible for the communication between the two . adopt Controller, We completely cut off the back-end and front-end . The decoupling of the system is realized .
splishsplash Medium Model Don't need to say more , Is the main body of calculation , Think of it as FluidModel And other examples of calculation data .
View It stands for GUI, At present, the default is IMGUI.
and Controller, It is GenericParamerter This third-party library . This library is splishsplash Another project developed by the project team . stay splishsplash As a third-party library . Its purpose is to manage parameters . As long as you want to Model The parameters in and the parameters of the user interface communicate with each other , It can be GenericParameter As the parent of your current class .GenericParameter Will be responsible for and IMGUI Communicate with each other . that , For our code developers , Just need to be able to use GenericParameter Of API Can be realized with GUI Communication between .
You may ask why you want to add an intermediary , Instead of going directly to Unicom IMGUI Well ? as a result of 1)GUI There are many options for libraries ,IMGUI,TweakBar( Once the default GUI) wait . If I change GUI, Wouldn't all the code in the algorithm have to change ? So for the sake of unity API, Adding an intermediary is beneficial .2) If there is no intermediary Controller, The code of communication between the two , Or write it in the GUI In the source file of , Or write it in the source file of the algorithm , Both of them will cause very troublesome coupling problems .3) Simplified use .IMGUI There are many functions , But we only need to manage parameters here , What is superfluous is a burden for us .
therefore , Next, we only focus on this intermediary Controller( That is to say GenericParameters) Of API.
Explain how to use
Let's look at an example , Code from SurfaceTensionBase.cpp
SURFACE_TENSION = createNumericParameter("surfaceTension", "Surface tension coefficient", &m_surfaceTension);
setGroup(SURFACE_TENSION, "Surface tension");
setDescription(SURFACE_TENSION, "Coefficient for the surface tension computation");
RealParameter* rparam = static_cast<RealParameter*>(getParameter(SURFACE_TENSION));
rparam->setMinValue(0.0);
The function of this code is : Binding parameters m_surfaceTension To GUI Up ,GUI The parameters shown in are called surfaceTension.
We analyze it line by line :
first line
SURFACE_TENSION = createNumericParameter("surfaceTension", "Surface tension coefficient", &m_surfaceTension);
createNumericParameter This function is to create a numeric parameter . The name of this parameter is surfaceTension( This name also applies to json file ). Described as Surface tension coefficient, The bound parameter is m_surfaceTension( Note that the pointer is passed ). As for the integer variable returned , yes GUI Group number of . It must be a static Of ( Because static lifetime is required )
The second line
setGroup(SURFACE_TENSION, "Surface tension");
For the convenience of management , Parameters are usually grouped . This is in GUI The above effect is paging . Each group is a separate page to display .
The third line
setDescription(SURFACE_TENSION, "Coefficient for the surface tension computation");
Description displayed when the mouse hovers .
In the fourth row
RealParameter* rparam = static_cast<RealParameter*>(getParameter(SURFACE_TENSION));
Used to set the maximum and minimum value . This is to prevent users from entering incorrectly .
The fifth row
rparam->setMinValue(0.0);
Set minimum value
Let's modify the experimental effect
I've just finished talking about the principle and usage , So let's try to change something , See if the theory conforms to practice .
Change the name, description and initial value of the test
The first line is changed to
SURFACE_TENSION = createNumericParameter("thisIsName", "This is Discription", &m_surfaceTension);
Compile operation 
We found that it was
Then whether it can pass json Change its parameters ? At present, the default is 0.05
We're in a json Change in
"Materials": [
{
"id": "Fluid",
"thisIsName": 1.11
}
],
function 
It is found that the parameters are indeed read
Test groups
The second line is changed to
setGroup(SURFACE_TENSION, "A new group");
Compile operation
When you choose any SurfaceTension New groups will appear when the algorithm 

And our previous parameter has also been moved to the new page .
Please note that : Decide whether your parameters are in the new page , Is the group of your parameters ( That is, the group number SURFACE_TENSION Determined by )
For example, the original Boundary surface tension coeff There is no new lease “A new group”
Test group description
Different from the previous one , This is a description of each variable in the Group
setDescription(SURFACE_TENSION, "This is the group discription");

Test the maximum and minimum values
The fifth line is changed to
rparam->setMinValue(1.0);
rparam->setMaxValue(5.0);
Suppose we type 0.9, Will automatically bounce back 1.0
The maximum is the same
边栏推荐
- Roewe rx5's "a little more" product strategy
- China BMS battery management system Market Research Report (2022 Edition)
- Research Report on development monitoring and investment prospects of China's smart environmental protection industry (2022 Edition)
- Hidden Markov model (HMM): model parameter estimation
- 【Try to Hack】vulnhub DC4
- SQL注入漏洞(Mysql与MSSQL特性)
- 剑指 Offer II 105. 岛屿的最大面积
- String class
- redis -- 数据类型及操作
- Leetcode records - sort -215, 347, 451, 75
猜你喜欢

多线程并发之CountDownLatch阻塞等待

Redis distributed lock

(17) DAC conversion experiment

String class

Soft test network engineer full truth simulation question (including answer and analysis)

整形数组合并【JS】

Leetcode records - sort -215, 347, 451, 75

Sword finger offer 20 String representing numeric value

字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化

SQL注入漏洞(Mysql与MSSQL特性)
随机推荐
Encryption and decryption of tinyurl in leetcode
股票万1免5证券开户是合理安全的吗,怎么讲
Gold, silver and four want to change jobs, so we should seize the time to make up
Vulnhub range hacksudo Thor
C language implementation of sum of two numbers [easy to understand]
Yyds dry inventory MySQL RC transaction isolation level implementation
Reflective XSS vulnerability
China acetonitrile market forecast and strategic consulting research report (2022 Edition)
Depth first traversal and breadth first traversal [easy to understand]
拼接字符串,得到字典序最小的结果
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
中国冰淇淋市场深度评估及发展趋势预测报告(2022版)
PHP实现敏感词过滤系统「建议收藏」
Report on Market Research and investment prospects of ammonium dihydrogen phosphate industry in China (2022 Edition)
ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing
Introduction to software engineering - Chapter 6 - detailed design
Openlayers customize bubble boxes and navigate to bubble boxes
【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam
智能运维实战:银行业务流程及单笔交易追踪
Develop those things: easycvr cluster device management page function display optimization