当前位置:网站首页>[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
边栏推荐
- 如何使用 etcd 实现分布式 /etc 目录
- Gameframework eating guide
- Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
- Redis Distributed Lock
- 为什么你要考虑使用Prisma
- [C language supplement] judge which day tomorrow is (tomorrow's date)
- GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
- Vulnhub range hacksudo Thor
- String的trim()和substring()详解
- Transition technology from IPv4 to IPv6
猜你喜欢

SQL injection vulnerability (MySQL and MSSQL features)

Redis distributed lock

Countdownlatch blocking wait for multithreading concurrency

Redis6.0 new features

SQL question brushing 1050 Actors and directors who have worked together at least three times

Kia recalls some K3 new energy with potential safety hazards

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

【C补充】【字符串】按日期排序显示一个月的日程

(十六)ADC转换实验

Sword finger offer 20 String representing numeric value
随机推荐
中国生物降解塑料市场预测与投资战略报告(2022版)
Redis6.0 new features
Is it safe to open an ETF account online? What are the steps?
【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam
Object. fromEntries()
【C补充】【字符串】按日期排序显示一个月的日程
Report on research and investment prospects of China's silicon nitride ceramic substrate industry (2022 Edition)
Please, stop painting star! This has nothing to do with patriotism!
字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
[flask introduction series] cookies and session
How wild are hackers' ways of making money? CTF reverse entry Guide
SQL injection vulnerability (MySQL and MSSQL features)
unity3d扩展工具栏
(十六)ADC转换实验
中国冰淇淋市场深度评估及发展趋势预测报告(2022版)
期货先锋这个软件正规吗安全吗?选择哪家期货公司更安全?
libcurl下载文件的代码示例
《中国智慧环保产业发展监测与投资前景研究报告(2022版)》
在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
The amazing open source animation library is not only awesome, but also small