I am building a SAPUI5 page, which will actually be one page with many tabs, and the tabs will each be based on a default component with the option to change it to a special purpose component.
I am thinking of using ComponentContainer here.
So it will be possible that we have 4 tabs: 3 based on component C1 - default, and 1 based on component C2 - special.
Is it possible to call from the controller of component C1 / C2 a function in the controller of the main APP (the one with tabs)?
Is it better to build a solution on calling a function in controller C1 / C2 from a separately created library?
The assumption is that a set of default functions will be prepared, but component can override the function.
So C1 will execute e.g. the standard function X () and Z (), and C2 is to overwrite the function X () and perform the standard function Z ().
The solution can be expanded, so copying the functions to each new component is omitted - it will be difficult to modify in the future.
The components will contain dynamically generated content based on the configuration in ERP.
Related
I'm trying build a framework which starts with reading an input file which contains some keys and corresponding values. I then update the variables accordingly:
from Inertia import Inertia
...
d = hf.read_input(fin)
locals().update(d)
Then, I'm defining the group MDA:
class MDA(om.Group):
class ObjCmp(om.ExplicitComponent):
def setup(self):
...
def setup_partials(self):
...
def compute(self, inputs, outputs):
...
def setup(self):
...
which contains two subsystems (for now):
self.add_subsystem('d1', SomeModule(), promotes_inputs=['x1','x2'],
promotes_outputs=['y1','y2'])
self.add_subsystem('obj_cmp', self.ObjCmp(), promotes_inputs=['y1'],
promotes_outputs=['obj'])
For housekeeping reasons, since the framework will eventually contain large number of subsystems, I want to keep the classes defining the particular subsystems in separate scripts, imported the the main script (the one where the Group is defined).
The problem I'm facing is that if I only read the input file once at the level of the script where the Group is defined (before entering the Group() class), the variables retrieved this way are not defined at the lower levels, for instance, I cannot use them inside SomeModule(). I'd normally define an init() method inside SomeModule() to be able to pass some variables:
def __init__(self, d):
self.d = d
but since we instantiate the SomeModule() class within self.add_subsystem(), it does not work.
I would be really grateful for any hints.
In OpenMDAO, we deal with this instantiation timing issue in two ways:
We strongly discourage the use of the __init__ method for components or groups. Instead, we recommend you rely on the initialize and setup methods. initialize is called inside the existing __init__ (i.e. at instantiation time). setup is called much later during the build up of the model hierarchy.
We do provide a means of creating init arguments via an options system. Options allow for some built in validation and also give you the chance to change the values later if you want to.
Delaying as much as possible till setup, if you can. Pass your configuration file (or an object built from it if you prefer) into your component as an option, but don't actually use it till setup.
This goes for both components and groups. You can make the configuration data an option at all levels of your groups. They will each pass the object down to their children inside their own setup methods. This way, you only need to have the object in existence by the time you initialize the top level group. It will then pass it down to all its children.
I trying implement UVM RAL for my project, and now faced with problem. For example I have 2 registers - reg A and reg B. I create classes for both, but from device spec value in field A.field1 mapping from B.field2. How I can implement this in UVM RAL.
Thanks.
You are probably looking to use aliased registers. The concept is described in the uvm user guide in section 5.7.3 .(page 114 )
http://accellera.org/images/downloads/standards/uvm/uvm_users_guide_1.1.pdf
The example in the umm user guide uses a couple of concepts and the same concept can be used to generate the aliasing for the A.field1 and B.field2.
A call back mechanism
A call back can be set up for the post predict function of the reg B.field2 . Every time ,after the value of B.field2 changes the post-predict function is triggered. In the post predict function the field value of register A ( A.field1) is also updated [ by calling the field1.predict ]reflecting the change/linkage. ( assuming A.field1 is dependent/alias of B.field2)
wrapper class
Create a wrapper class which will connect the fields from both these registers (A & B - A.field1 to B.field2) and instantiate the wrapper class. The wrapper class also registers the callback for register B field2. If the register model is auto generated the wrapper class can be instanced outside the register model , else like in the example inside the model itself.
You can use a callback mechanism, “uvm_reg_cbs” specifically as per your requirement. In this class, there are predefined functions like pre_write() , post_write() , post_predict() etc. which provide the flexibility in interdependency between registers.
You can extend your register (Reg A) class with "uvm_reg_cbs" and register this callback with another register (Reg B).
I have an GWT module, which defines an entry point that builds an UI (let's call this module A).
I inherit module A in another module (say module B), which builds its own UI via its own entry point, reusing classes defined in inherited module A.
My problem is, when I initialize module B, entry points from both Module A and B are instantiated and triggered (via onModuleLoad method). This results in both entry points modifying same UI in turn, resulting in corrupt page.
So, I want to inherit a module, but I don't want its entry points activated during application initialization. How can I inherit a module, but avoid initialization of its entry point class?
Instead of inheriting A from B, and adding more entrypoints that need to be built, consider making a third module. The new one, Z should be the common code that both A and B need, and should not have an entrypoint. This way, both A and B can inherit from Z and each add their own entrypoint as needed.
If the above can't be used (for example if you can't edit A), another option could be to add a new module in the same package as A, call it A2, and give it the same contents of A, minus the EntryPoint. Then, B can inherit from A2 instead.
I have a structure called "uwb" in the base workspace. Under the uwb structure I have another structure called "channel". Under channel I have got two variables, a and b. Now I want to create a subsystem. I want to mask the block. My problem is I have to use the variables a and b for the initialization of the masked subsystem. How can I include a and b in initialization commands of the subsystem while masking?
After creating a mask for the subsystem:
Select the Parameters tab in the subsystem mask editor to add tunable dialog parameters.
Add the dialog parameters for each variable you need to access (i.e. call them maska and maskb).
Head over to the Initialization tab and add your initialization code referring to the dialog parameter names maska and maskb. Apply your changes close the mask editor window.
Double click on the masked subsystem and you should be prompted to enter values for the two dialog parameters that were just setup.
In the textfields, type in the workspace variables uwb.channel.a and uwb.channel.b to assign their values to maska and maskb respectively.
As long as the uwb struct is in the base workspace when the model is initialized to run, the masked subsystem will evaluate and assign the a and b appropriately.
(I just tried it out and it seems to work fine, here is the model as a reference: http://sfwn.in/Fejp)
I am implementing a plugin system with Lua scripts for an application. Basically it will allow the users to extend the functionality by defining one or more functions in Lua. The plugin function will be called in response to an application event.
Are there some good open source plugin frameworks in Lua that can serve as a model?
In particular I wonder what is the best way to pass parameters to the plugin and receive the returned values, in a way that is both flexible and easy to use for the plugin writers.
Just to clarify, I am interested in the design of the API from the point of view of the script programming in Lua, not from the point of view of the hosting application.
Any other advice or best practices related to the design of a plugin system in Lua will be appreciated.
Lua's first-class functions make this kind of thing so simple that I think you won't find much in the way of frameworks. Remember that Lua's mantra is to provide minimal mechanism and let individual programmers work out policy for themselves.
Your question is very general, but here's what I recommend for your API:
A single plugin should be represented by a single Lua table (just as a Lua module is represented by a single table).
The fields of the table should contain operations or callbacks of the table.
Shared state should not be stored in the table; it should be stored in local variables of the code that creates the table, e.g.,
local initialized = false
return {
init = function(self, t) ... ; initialized = true end,
something_else = function (self, t)
if not initialized then error(...) end
...
end,
...
}
You'll also see that I recommend all plugin operations use the same interface:
The first argument to the plugin is the table itself
The only other argument is a table containing all other information needed by the operation.
Finally, each operation should return a result table.
The reason for passing and returning a single table instead of positional results is that it will help you keep code compatible as interfaces evolve.
In summary, use tables and first-class functions aggressively, and protect your plugin's private state.
The plugin function will be called in response to an application event.
That suggests the observer pattern. For example, if your app has two events, 'foo' and 'bar', you could write something like:
HostApp.listeners = {
foo = {},
bar = {},
}
function HostApp:addListener(event, listener)
table.insert(self.listeners[event], listener)
end
function HostApp:notifyListeners(event, ...)
for _,listener in pairs(self.listeners[event]) do
listener(...)
end
end
Then when the foo event happens:
self:notifyListeners('foo', 'apple', 'donut')
A client (e.g. a plugin) interested in the foo event would just register a listener for it:
HostApp:addListener('foo', function(...)
print('foo happened!', ...)
end)
Extend to suit your needs.
In particular I wonder what is the best way to pass parameters to the plugin and receive the returned values
The plugin just supples you a function to call. You can pass any parameters you want to it, and process it's return values however you wish.