Start a new topic

Creator Plugin

Original Post by: Sat Oct 25 06:57:56 2014


Hi,


I want to create a plugin in creator with customised attribute searches. can someone direct me how can i do it. like major steps. just like other tool boxes it should have a tool box.


Original Post by: SteveThompson Tue Nov 18 19:40:03 2014


Here is some sample code that should get you started:

Note that this is C++, it you want plain C you might have to tweak some things, like the static_cast, etc.


// a simple "round" function, used below to convert from API color index/intensity to

// Creator color index.

static float MY_ROUND(float f)

{

return (float)floor(f + 0.5);

}


// this is the mgWalk pre-visit callback. it is called by mgWalk as all the nodes in the

// db are traversed and visited.

static mgbool SelectCallback (mgrec* db, mgrec* parent, mgrec* rec, void* context)

{

toolrec* toolRec = static_cast<toolrec*>(context);


// check what kind of node we are visiting now

if (mgGetCode(rec) == fltPolygon)

{

int colorIndex = -1;

float intensity = 1.0f;

// if it's a polygon, check its color index

int numAttr = mgGetAttList(rec, fltPolyPrimeColor, &colorIndex;,

fltPolyPrimeIntensity, &intensity;, MG_NULL);

if (numAttr == 2)

{

// Color index is tricky.

// The API represents color as index and intensity. index in range 0..2047, intensity range 0..1

// Creator combines index and intensity into another (Creator) color index in range 0..131071

// if you want color index 127 (that's Creator color index), you need to convert from API color

// index and intensity to Creator color index range. This formula does this.

int creatorColorIndex = (colorIndex * 128) + (int)(MY_ROUND(intensity * 127.0f));

if (creatorColorIndex == 127)

mgSelectOne(rec);

}

}

return MG_TRUE;

}


// this is the callback function we will assign to our button. we set it up

// to get called for both the Activate and Refresh control events

static mgstatus SearchButtonCallback (mggui gui, mgcontrolid controlId,

mgguicallbackreason callbackReason,

void* userData, void* callData)

{

toolrec* toolRec = static_cast<toolrec*>(userData);


switch (callbackReason)

{


// MGCB_ACTIVATE is sent when the user "presses" the button

case MGCB_ACTIVATE:

// first make sure nothing is selected

mgDeselectAll (toolRec->db);

// "walk" the database, visit every node, find / select polygons with Creator Color index 127

mgWalk (toolRec->db, SelectCallback, NULL, toolRec, 0);

break;


// MGCB_REFRESH is sent when the button should "refresh" itself, it could change the

// caption or enable/disable/hide the button, etc

case MGCB_REFRESH:

break;

}

return (MSTAT_OK);

}


static void InitializeGuiCallbacks (toolrec* toolRec)

{

mggui gui = MG_NULL;


// assign the callback to the button whose ID is BTN127 (your button ID)


if (gui = mgFindGuiById (toolRec->dialog, BTN127))

mgSetGuiCallback (gui, MGCB_ACTIVATE|MGCB_REFRESH, SearchButtonCallback, toolRec);

}


Hopefully this gets you farther.

Original Post by: Wed Nov 19 12:56:10 2014


You know I never asked, but why aren't you just using Attribute Search in Creator? Do you need a special plugin to do this? I understand if you just want to learn but do you really have a need for a special plugin to do what Attribute Search does already?

I'm still using the attribute search itself sir, there are few newbies joined our firm which they are getting familiar with checklists and terms, so they are finding difficult in searching appropriate attribute names from attribute search. so to make their and my tasks easy i'm trying to float all these searches and few other attributes accessible in one click.

Sorry if I'm disturbing you too much.

Original Post by: Wed Nov 19 13:02:55 2014


...But im not able to add an icon to that.

The code you wrote to create the mgpixmap is not correct:

mgpixmap pixmap = mgResourceGetPixmap (resource, "REMOTEV2.BMP");


You need to add a "Bitmap" resource to your .rc file. When you do this you bind a bitmap file (.bmp) to a resource id. Instead of passing the .bmp name to mgResourceGetPixmap you pass the resource id of the bitmap resource.


If programming with Windows Resource Files is new to you, you might need to study the MicroSoft help topics on line. Windows Resource Files are not specific to the OpenFlight API, they are a standard way for Windows applications to describe Graphical User Interfaces. Creator and plugins in Creator use this standard technology to make plugins GUIs.


You can also check the many sample plugins that came with the OpenFlight API SDK. The one called guitest might be of particular interest to you as it shows how to do many things in your dialog and will show you how to assign bitmap files to bitmap resources and then to your GUI elements.


I got hold on resources and the way to bind them. Thank you

Original Post by: Wed Nov 19 14:44:02 2014


Sir i tried the code you gave, and i leaned lot of things from that, but when i run the plugin nothing is happening to polygons, i mean they are not getting selected even if their primary color indices are 127.


As you mentioned i tweaked code to comply with C.

Please see the attached image for what i meant by 127 if i'm wrong this image can give you an idea of what i'm referring to. :)

Original Post by: SteveThompson Wed Nov 19 14:48:40 2014


I’m still using the attribute search itself sir, there are few newbies joined our firm which they are getting familiar with checklists and terms, so they are finding difficult in searching appropriate attribute names from attribute search. so to make their and my tasks easy i’m trying to float all these searches and few other attributes accessible in one click.

Sorry if I’m disturbing you too much.

It is no bother. It just seems like a lot of work for you to make a plugin rather than figuring out the correct search terms in Attribute Search. We are happy to help in whatever you decide is best for your firm ;-)

Original Post by: SteveThompson Wed Nov 19 14:56:58 2014


Sir i tried the code you gave, and i leaned lot of things from that, but when i run the plugin nothing is happening to polygons, i mean they are not getting selected even if their primary color indices are 127.

Hmmm... not sure how I can help you with this one. The code I sent you worked in my sample plugin so I don't know why it would not work for you. Perhaps you could run it through the debugger and see what might be the problem. Since you "tweaked" it a bit perhaps something was not quite right. Your best plan would be to use the debugger to follow the code and see what parts are not working the way you expect.


BTW I know you plan to add additional searches on this plugin but Attribute Search can do this one very easily ;-) We're still happy to help with your plugin. Let us know what you find out in the debugger.

Original Post by: Wed Nov 19 17:07:23 2014


Hi sir please find the attached code for the same and let me know what could be the reason.

there is no error or warnings while debug/build.

Also attaching the debug log.

Original Post by: SteveThompson Wed Nov 19 17:17:03 2014


I can look at this code but I think you misunderstood my suggestion. At some point you will have to dig in and run your plugin using the "debugger" in Visual Studio. When you do this, you can determine exactly why some code works or does not work. We can "look" at code all day but you are the only one that can run it. You need to become comfortable with the VS debugger or will struggle a lot.


I'll look at this code while you dig into the debugger. And by that I mean you need to "step through" the code line by line, examine values of variables, follow if then else blocks etc. Once you master this, you will be able to tell why your code does not work.

Original Post by: SteveThompson Wed Nov 19 17:19:55 2014


I don't see anything wrong with this code. The only thing that can solve this is you running the debugger. Good luck.

Original Post by: Wed Nov 19 17:34:29 2014


I can look at this code but I think you misunderstood my suggestion. At some point you will have to dig in and run your plugin using the "debugger" in Visual Studio. When you do this, you can determine exactly why some code works or does not work. We can "look" at code all day but you are the only one that can run it. You need to become comfortable with the VS debugger or will struggle a lot.


I'll look at this code while you dig into the debugger. And by that I mean you need to "step through" the code line by line, examine values of variables, follow if then else blocks etc. Once you master this, you will be able to tell why your code does not work.


sure sir.. i'll.

Original Post by: SteveThompson Wed Nov 19 17:45:35 2014


sure sir.. i’ll.

Please, you can call me "Steve" ;-)

Original Post by: Thu Nov 20 12:08:31 2014


I got my plugin working apart from selecting polygons,

now it will load materials and apply them according to database type, it will clear projections values, and all useful checklists. Thanks a lot Steve :).


But i want the window to be floated on till user manually closes it. now if i open another tool my dialog box is getting hidden or destroyed. i want to be remain opened unless user manually closes it.

Original Post by: SteveThompson Thu Nov 20 17:47:29 2014


But i want the window to be floated on till user manually closes it. now if i open another tool my dialog box is getting hidden or destroyed. i want to be remain opened unless user manually closes it.

That is because you made it an Editor tool. Only one editor tool can be open at one time per database. It is problematic if two tools are "changing" the database at the same time. If you want the tool to be open all the time you need to make it a Viewer tool. Since your tool only selects, making it a Viewer is certainly reasonable. If your tool, in any way, modifies the database, it should be an Editor.

Original Post by: Fri Nov 21 12:15:44 2014


Thanks for the info on Editor and Viewer, i compiled and the plugins are working on my system but its not working on other systems when i tried copying it to others. What i did is i copied the dll file which is build and copied it to the plugins folder. Is there anything else i have to do in this.

Original Post by: SteveThompson Fri Nov 21 17:31:34 2014


i compiled and the plugins are working on my system but its not working on other systems when i tried copying it to others. What i did is i copied the dll file which is build and copied it to the plugins folder. Is there anything else i have to do in this.

Make sure exit and re-start Creator on that other system after you drop the DLL into the plugins folder.

Also make sure you are copying into the correct plugins folder in case you have multiple versions of Creator installed.


When Creator starts, it writes to the Status Log all the plugins it tries to load. Check Info>Status Log in case there is a message trying to tell you why this DLL could not load.

Login to post a comment