Idea

Hao Zhou avatar image
4 Likes"
Hao Zhou suggested Hao Zhou edited

Let user create custom FlexScript Interface in a model instead of only in Module SDK

The latest module SDK is ready to let user create custom FlexScript interface. Is it possible to add a feature that let user also be able to create custom FlexScript Interface in a model?

For example, you can create a new GUI called "User Classes", which is similar to user commands. In the GUI, user is able to create a class structure as follows:

Class MyCustomClass
{
	int myInt; // Member variable with type int
	double myDouble; // Member variable with type double
	Table myTable; // Member variable with type Table
	Object myObj; // Member variable with type Object
	TrackedVariable content; // I want to track content in the data structure
	TrackedVariable state; // My custom state profile

	static void init(treenode t);
	int getMyInt();
	int setMyDouble();
	int updateContent();
	int setState(int stateNum);
	...
}

User may use the custom class as follows:

MyCustomClass cs = MyCustomClass.init(t);
cs.setMyDouble(2.0);
cs.updateContent();
...

Technically, I guess user classes may be bound as a SDT. Member variables and functions may be bound in bindinterface() in the background. I am not quit sure.

The advantages are as follows:

1. Encapsulate model specific data structure. During modelling, there are always some case you need to create custom data structure. For example, see attached image, I would like to simulate parking lot by network node system. Each park lane is a network node. For a parking lot, I need to record pointers of lanes, lane capacity, and current content. I also need to record which traveler reserved the lane and which traveler is waiting to enter the full parking lot. I also want to tracked parking lot content and throughput, etc. What I am doing right now is that I create the tree structure to represent the data structure. I also create a lot of user command to operate the date structure. If I can create "User Classes", variables and functions can be encapsulated in an object-oriented way. It avoids potential error of calling wrong user commands since compiler will tell you if you are called the right class functions or not.

2. It can reduce the number of user commands. Imagine that a big model with more than 200 user commands is hard to manage and error-prone.

3. You do not have to put all your stuff into module in order to have the benefits of dot syntax.

4. It may reduce of the number of macro definition.

5. If you have multiple model data structures, these data structure can have same-signature member functions. Right now, you have distinguish them by defining user commands with different names.

6. It makes your FlexScript code look more object-oriented.

custom flexscript interface
1.png (17.1 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

No Comments

·

Write a Comment

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.

Related Ideas