plugins and gui components ...

Development of custom GMAT plugins

plugins and gui components ...

Postby marchand » Wed Mar 27, 2013 6:13 pm

I have a few questions that the developer's plug-in documentation does not seem to address. For the most part, I am having to work with the existing plug-ins as models in this regard. In trying to answer some of my questions, I came across some interesting "features" that I cannot explain on the plug-ins that currently release with GMAT, specifically the GUI component. I have posted a video illustrating the problem in the link below:

https://engineering.purdue.edu/~marchand/gmat-plugin-estimation-errors/gmat-plugin-estimation-errors.html

To illustrate, consider two examples, the fmincon optimizer plug-in and the estimation plug-in. Both have resources that appear in the GMAT gui. The fmincon resource object behaves as expected in regards to the Clone, Rename, and Delete options, but the same cannot be said for any resource tied to the Estimation plug-in. A close-up look at the source does not reveal an immediately obvious reason for this problem. Since I am trying to create my own plug-in, with resources that would appear in the GUI, it would be helpful to know the reason for the problem.

Right now, if I create a resource under Solvers --> SQP (fmincon), I am able to rename that object, delete it, or clone it. If, instead, I create Solvers --> Estimators --> BatchEstimatorInv, and thus create a resource named BatchEstimatorInv1, I cannot delete the resource once it is created, and I cannot rename it. The operation returns an internal error, **** INTERNAL ERROR **** ResourceTree::GetObjectType() unknown item type: 41750. Also, Cloning does not "appear" to do anything, but it must be doing something internally, at least partially, and just not having the desired effect externally. For instance, if I right-click on BatchEstimatorInv1 and select Clone, I would expect to see another resource called BatchEstimatorInv2 appear on the resources tab under Solvers --> Estimators. Instead, nothign happens. However, if I then try to rename BatchEstimatorInv1 to BatchEstimatorInv2, it says it can't because that object already exists. So, clearly, it created a clone internally, but it does not appear in the resources window.

I looked at the source code for the fmincon optimizer plug-in and the estimator plug-in, and the reason for this problem is not evident. Does anyone know why this is happening and how to fix it? It would be helpful to know why this is happening, if anyone has already figured it out. I seem to recall, in a recent discussion, a mention to some problems with the Estimation GUI. Perhaps this is what folks were talking about?

--B.
marchand
 
Posts: 86
Joined: Tue Feb 21, 2012 2:42 pm

Re: plugins and gui components ...

Postby shughes » Wed Mar 27, 2013 10:41 pm

Hi Belinda,

As I mentioned a few weeks ago, when our funding for the Estimation plugin ran out, out of obligation we just stopped working on it. So, it is in alpha status because it has not been completed. You are going to find a lot of issues like the ones you described above for this reason. I appreciate your frustration when you come across these issues, but that is why we turn it off in our releases and don't advertise it as mature functionality. It simply isn't done and it isn't tested beyond a handful of system tests.

There is an enormous amount of quality work there, including a great design infrastructure, but there is quite a bit of work to complete all of the odd and ends left undone. Sorry that is that state of the plug-in, but that is the honest assessment of it.

Steve
shughes
 
Posts: 443
Joined: Mon Jun 09, 2008 6:27 pm

Re: plugins and gui components ...

Postby marchand » Thu Mar 28, 2013 12:01 am

Thanks Steve. The main reason I bring this up is because I can't tell why the fmincon plugin doesn't have this problem but the estimation plugin does. I mean, if I look at the source, and compare the clone methods they look about the same the only difference is that the fmincon plugin has some hard wired elements in the GUI code and be estimation plugin does not. I'm actually running into the same problem with my own plugin at the moment, which is why I was wondering if anyone knew why the estimation plugin has that issue. I was using the estimation plugin as an example, perhaps that was a bad idea :-)

Since all these things inherit from GmatBase, why is it necessary to override Clone in the first place? Shouldn't the default work? Does that only address the scripting version of the object, and not the GUI? Is there another aspect that exists only in the GUI code related to cloning and deleting?

I'm thinking that is probably the case, and the reason why the fmincon plugin doesn't have that problem. Perhaps the only way to get around this is to hardware things in the GUI source, but I didn't get that impression from the documentation you had pointed me to earlier. My understanding was that all resources get a default GUI based on the public member variables. That is true, I can confirm. There wasn't anything in there about the deleting or cloning of resources on the GUI side though.
marchand
 
Posts: 86
Joined: Tue Feb 21, 2012 2:42 pm

Re: plugins and gui components ...

Postby DJCinSB » Fri Mar 29, 2013 3:09 pm

(Sorry for the brief response here -- my "must be fixed" count is moving the wrong direction this week!)

Just a quick note on this piece:
marchand wrote:Since all these things inherit from GmatBase, why is it necessary to override Clone in the first place? Shouldn't the default work? Does that only address the scripting version of the object, and not the GUI? Is there another aspect that exists only in the GUI code related to cloning and deleting?

If you read the GmatBase code, you'll see that the base class Clone method is defined like this in the header:
Code: Select all
   // required method for all subclasses
   virtual GmatBase*    Clone() const = 0;

and that there is no code for the method in the implementation code. That makes the method abstract ("pure virtual" in some C++ texts) and forces subclasses to implement it. That is done so that the engine code in the base library can work with pointers to base class objects and still create copies of derived class objects. As an example, suppose you have a Spacecraft named sat and a Formation named myForm in a ObjectArray container, and you want to copy these objects into a second container. ObjectArray is defined like this:
Code: Select all
typedef std::vector<GmatBase*>                 ObjectArray;

If we try to do something like this:
Code: Select all
// Defined earlier somewhere and filled with sat and myForm pointers: ObjectArray originals
ObjectArray spaceObjectCopies;

for (UnsignedInt i = 0; i < originals.size(); ++i)
   GmatBase *copy = new GmatBase(*originals[i]);

The problem here is that the compiler doesn't know the leaf class type of the GmatBase pointer at originals[i], so it doesn't know what type of object to create. Even if GmatBase wasn't an abstract class (meaning a class with pure virtual methods), the copy constructor called here would not produce the right leaf class type because the compiler would not be able to determine that type unambiguously. We avoid this issue by forcing the subclasses to override and implement the Clone() method, setting it to return an object created by the leaf class's copy constructor.

The base code implementing the GMAT engine uses this approach extensively. As an example, when an obect is cloned into a Sandbox, the clone is created with this line of code:
Code: Select all
      cloned = obj->Clone();

It's not a GUI specific item, though the GUI also uses this code for cloning Resources.
DJCinSB
 
Posts: 274
Joined: Mon Jun 09, 2008 3:57 pm

Re: plugins and gui components ...

Postby marchand » Fri Mar 29, 2013 4:32 pm

Thanks Darrel. My apologies, I should have been more specific in my question. The classes I'm extending extend other classes that extend GmatBase. So, in the hierarchy of dependencies, a Clone() method is eventually defined already. So, you are absolutely correct, the Clone method in GmatBase is abstract. However, to quote a better example, say I have a plug-in that extends the Spacecraft class, which already has a concrete definition of the Clone() method, and the Copy() method, and a destructor, etc. So, if my class extends Spacecraft, it inherits those methods already. I should not need to override them, or do I?

Before you answer that question, let me take a step back and point out that it's possible I may be misreading the plug-in development documentation. For example, in the plug-in documentation, in the discussion about the factory subsystem, it is suggested that your factory code should contain one of a list of available method calls, to define the appropriate object. For example, consider these two listed in the documentation:

Code: Select all
virtual SpaceObject* CreateSpacecraft(const std::string &ofType,const std::string &withName = "");

vs.
Code: Select all
virtual Solver* CreateSolver(const std::string &ofType,const std::string &withName = "");


The Estimation plugin's Estimator factory has a concrete definition of the CreateSolver method, which returns a pointer to a Solver. My plug-in has a concrete definition of the CreateSpacecraft method, which returns a pointer to a SpaceObject, not a Spacecraft which is a type of SpaceObject.

My factory has a method of the following form:

Code: Select all
   SpaceObject* PatchStateObjectFactory::CreateSpacecraft(const std::string &type, const std::string &withName) {
      if (type == "PatchState") {
         return new PatchState(withName,type);
      } else {
         return NULL;
      }
   }


where the PatchState constructor looks like this:

Code: Select all
PatchState::PatchState(const std::string &name, const std::string &typeStr)
   : Spacecraft(name, typeStr) {
      objectTypeNames.push_back("PatchState");

}


Is that not the correct approach? Should I be trying to extend SpaceObject instead? Perhaps the difference between the pointer type and the method name threw me off.

--B.
marchand
 
Posts: 86
Joined: Tue Feb 21, 2012 2:42 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests