How to communicate with iCustomGui?
-
On 03/03/2014 at 14:31, xxxxxxxx wrote:
Well...Talk to Niklas guys.
If he doesn't mind me posting a plugin that's 95% his code. I'll post it.
It's really up to him.-ScottA
-
On 03/03/2014 at 22:50, xxxxxxxx wrote:
Thank you Scott for waiting for my permission. Yes, you may make it public
Best,
-Niklas -
On 04/03/2014 at 00:47, xxxxxxxx wrote:
Great, thanks guys.
-
On 04/03/2014 at 01:27, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Thank you Scott for waiting for my permission. Yes, you may make it public
Fantastic, thanks!
-
On 04/03/2014 at 08:53, xxxxxxxx wrote:
Ok guys. You can grab it here.
https://sites.google.com/site/scottayersmedia/pluginsI don't own a mac. So it's only compiled for Windows.
But the source code is what you really want anyway.-ScottA
-
On 04/03/2014 at 10:41, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Ok guys. You can grab it here.
But the source code is what you really want anyway.Right! And thank you so much! I have seen similar things, like Niklas' Tristate example. The comments in the source code are what makes it so valuable, so I learnt from this!
What I am after, and what I meant with the thread topic title, is how to communicate with the iCustomGui when you have several gadgets in the same iCustmGui.
Look here, I extended Scott's User Data, by adding a Real Slider:virtual Bool CreateLayout() { //Attach the User Area to the custom GUI gizmo AddUserArea(1000, BFH_SCALEFIT, 0, 0); AttachUserArea(ua, 1000); **AddEditSlider(1001, BFH_SCALEFIT, 80);** return TRUE; }
But when using xpresso, I only have access to Scott's slider, not the added slider:
This is not a topic when using UserData like this. But it becomes interesting when using it in a RES file, to add gadgets to you tag.
While I now can send a few real values back and forth between my tag and the iCustomGui, I cannot replicate the SplineData behaviour, if you are familiar with that one.So my initial question in this thread remains, I do not know how to properly send data from my tag plugin to my iCustomGui, and read those data back, when the iCustomGui has several gadgets.
I have managed to do it somehow, but, I am almost sure, in an inadequate way.A full working example on how to do this, is what I want, with all files involved. It doesn't have to be fancy, actually just two Real gadgets wold do. I must be able to set the values of both from my tag, read back the values again, after they are changed by the user. And they must remember their positions when
a) the project is saved and closed, b) another tag is selected so that it loses focus.I am still almost in start position on this task, unfortunately.
-
On 04/03/2014 at 11:32, xxxxxxxx wrote:
Yeah.
Controlling the gizmo if it's added within the .res file and not with the UserData is still not known to me yet.
And one reason why I keep asking Maxon for an example of their slider gui code. So we can see what they're doing in there to make that work.
I get turned down every time I ask them for the code.-ScottA
-
On 04/03/2014 at 12:22, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Yeah.
Controlling the gizmo if it's added within the .res file and not with the UserData is still not known to me yet.I know how to do it in a way, but I doubt it is the correct way.
Originally posted by xxxxxxxx
Yeah.
And one reason why I keep asking Maxon for an example of their slider gui code. So we can see what they're doing in there to make that work.
I get turned down every time I ask them for the code.Well, I sent a mail ti dev support, - total silence..
One might think it would benefit Maxon, the end user - and us plugin writers - if we were taught how to do it the correct way. Well, maybe they do not have working examples, and I guess they have their days filled up.. -
On 04/03/2014 at 12:39, xxxxxxxx wrote:
Oh shoot.
I forgot to add this to the notes in the code. But I do know how to poll the slider's values when using this gizmo when it's created in the .res file instead of the UserData pallet.
I know you want to go the other direction and control the slider itself.
But this is how to get the value of the custom slider if it's been created in a .res file.Lets say that you're creating a tag plugin and you want to use this custom slider by creating it in the tag's .res file.
This is what the .res file should look like:CONTAINER tsimpletag { NAME tsimpletag; INCLUDE Texpression; GROUP ID_TAGPROPERTIES //The default tab named "TAB" { //"MYSLIDER" is the ID for the CUSTOMGUI gizmo hard coded within it's source code LONG MY_SLIDER_GIZMO { CUSTOMGUI MYSLIDER; MIN 0;} } }
Then in one of your tag's methods you can get the value of the slider like this:
Bool MyTag::Message(GeListNode *node, LONG type, void *data) { BaseTag *tag = (BaseTag* )node; //Get the tag and assign it to a variable BaseContainer *tagdata = ((BaseList2D* )node)->GetDataInstance(); //Get the container for the tag LONG sv = tagdata->GetLong(MY_SLIDER_GIZMO); //The value is very large(in pixels) so we chop it down to return 0-10 sv = sv/200000000; GePrint(LongToString(sv)); tag->SetDirty(DIRTYFLAGS_DATA); //Used to update a Tag's AM GUI items return TRUE; }
Not really what you're asking for.
But most people will probably just want to get the value of the slider. And that how to do it.
I should have included that information in the notes.-ScottA
-
On 25/03/2014 at 03:22, xxxxxxxx wrote:
Originally posted by xxxxxxxx
What I am after, and what I meant with the thread topic title, is how to communicate with the iCustomGui when you have several gadgets in the same iCustmGui.
Look here, I extended Scott's User Data, by adding a Real Slider:virtual Bool CreateLayout() { //Attach the User Area to the custom GUI gizmo AddUserArea(1000, BFH_SCALEFIT, 0, 0); AttachUserArea(ua, 1000); **AddEditSlider(1001, BFH_SCALEFIT, 80);** return TRUE; }
But when using xpresso, I only have access to Scott's slider, not the added slider:
This is not a topic when using UserData like this. But it becomes interesting when using it in a RES file, to add gadgets to you tag.
While I now can send a few real values back and forth between my tag and the iCustomGui, I cannot replicate the SplineData behaviour, if you are familiar with that one.So my initial question in this thread remains, I do not know how to properly send data from my tag plugin to my iCustomGui, and read those data back, when the iCustomGui has several gadgets.
I have managed to do it somehow, but, I am almost sure, in an inadequate way.A full working example on how to do this, is what I want, with all files involved. It doesn't have to be fancy, actually just two Real gadgets wold do. I must be able to set the values of both from my tag, read back the values again, after they are changed by the user. And they must remember their positions when
a) the project is saved and closed, b) another tag is selected so that it loses focus.I am still almost in start position on this task, unfortunately.
Have you created an iCustomDataType for your iCustomGUI? Since you now display two values in
your GUI, it can not be represented by a single float value anymore which is why it needs its own
new datatype.Best,
-Niklas -
On 25/03/2014 at 03:37, xxxxxxxx wrote:
Hi Niklas,
> Have you created an iCustomDataType for your iCustomGUI?
Yes, I tried at least._> Since you now display two values in your GUI, it can not be _
> represented by a single float value anymore
I understand this!> which is why it needs its own new datatype.
I understand this too!What I need, is a fully working example on how to do this.
It is a long time since I posted my first question in this thread, and in the mean time, I have found a sort of a solution by passing a BaseContainer between my Tag plugin, and my iCustomGui. But I still do not know how to employ the iCustomDataType.So on my wishlist is a fully working example on how to communuiate between a BaseTag and a iCustomGui, using the iCustomDataType. Because this is still Greek to me..
-
On 25/03/2014 at 03:52, xxxxxxxx wrote:
Hi Ingvar,
out of interest, how do you communicate between your Tag and iCustomGui?
I'll try to make an example this week, it is on my Todo list.
Best,
-Niklas -
On 25/03/2014 at 04:24, xxxxxxxx wrote:
Hi Niklas
virtual Bool SetData(const TriState<GeData> &tristate) { const GeData &value = tristate.GetValue(); if(value.GetContainer()) { BaseContainer* bc = value.GetContainer(); Real fooReal = bc->GetReal(12345); LONG fooLong = bc->GetLong(6789); Bool fooBool = bc->GetBool(654321); } }
virtual Bool GetData(const TriState<GeData> &tristate) { BaseContainer bc; bc.SetReal(12345, 3.14); bc.SetLong(6789, 2014); bc.SetBool(654321, TRUE); GeData geContainer(bc); return TriState<GeData>(geContainer); }
By passing a BaseContainer between the tag and the custom GUI, I can send a bunch of data in one operation.
When reading this code, you have to take into consideration that it is simplified, I have removed all the normal validity and safety checks.
In the tag, I can just use SetParameter() and use a BaseContainer that I create on the fly, fill it up with data, and use it as the second parameter. The first parameter is the ID of the Custom GUI.
For the record, I had to concentrate on other tasks the last couple of weeks, so this topic is out of my head at the moment, but I will come back.I am really looking forward to a working example. Please use the BaseTag plugin type, and no Dialog or Command plugin. I do understand the iCustomDatatype if the user needs to add CustomData to the tag. But I do not understand the purpose of it when communicating between the tag and the GUI.
And - keep the example simple, if possible
-
On 25/03/2014 at 16:07, xxxxxxxx wrote:
Hi ingvar,
I see, thanks for the info. Didn't think of containers for that use case, neat workaround.
By the way, it just appeared to me that the SDK example in source/datatype/datatype.cpp actually
does what you want, exposing the parameters to XPresso. It lacks the comments completely,
though. I'll still be making an example.Best,
-Niklas -
On 25/03/2014 at 16:46, xxxxxxxx wrote:
Hi Niklas,
I found the datatype.cpp example some weeks ago. And I have turned the datatype.cpp inside out, upside down, das ganze auf den Kopf gestellt - I still do not see how that can help me communicate with the custom GUI.
For the User data - I can understand its purpose, but not for the communication between a BaseTag and a CustomGui.Please note this: We might be talking about different things.
It is not about the User Data, like the image you posted above. It is about making a Custom Gui for my tag. I want to make a custom gui, like the SplineData GUI, just as an example.
My concern is the communication between the BaseTag and the CustomGui. Which I somehow have solved, using the BaseContainer.But let us look at the SplineData Custom Gui.
If I had Maxon's soure code for this, I might understand how it works. Have you seen all the code you need to write in order to programmatically add knots to the SplineData Custom GUI?
I know how to write the code in C++ for doing this, add knots and set the tangents. Because I found the source code for doing this here in this forum, or elsewhere on the Internet.
But I have absolutely no clue whatsoever why it has to be done this way. -
On 01/04/2014 at 11:33, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Hi Niklas,
I found the datatype.cpp example some weeks ago. And I have turned the datatype.cpp inside out, upside down, das ganze auf den Kopf gestellt - I still do not see how that can help me communicate with the custom GUI.
For the User data - I can understand its purpose, but not for the communication between a BaseTag and a CustomGui.Please note this: We might be talking about different things.
It is not about the User Data, like the image you posted above. It is about making a Custom Gui for my tag. I want to make a custom gui, like the SplineData GUI, just as an example.
My concern is the communication between the BaseTag and the CustomGui. Which I somehow have solved, using the BaseContainer.But let us look at the SplineData Custom Gui.
If I had Maxon's soure code for this, I might understand how it works. Have you seen all the code you need to write in order to programmatically add knots to the SplineData Custom GUI?
I know how to write the code in C++ for doing this, add knots and set the tangents. Because I found the source code for doing this here in this forum, or elsewhere on the Internet.
But I have absolutely no clue whatsoever why it has to be done this way.Hi ingvar, I am working on an example for you. Your BaseContainer approach is not bad at all
actually, less work than implementing your own CustomDataType.The only way to communicate between your tag and your CustomGUI is by passing the appropriate
data from the tag to your CustomGUI. You solved it with a BaseContainer, the SplineGUI has its
own CustomDataType.The BitmapButtonCustomGui is a very good example for this. Its custom datatype has a pointer
to the BaseList2D (in your case the tag) that uses the custom GUI. The Custom GUI uses this
pointer to invoke the MSG_DESCRIPTION_GETBITMAP message on it.Originally posted by xxxxxxxx
Have you seen all the code you need to write in order to programmatically add knots to the SplineData Custom GUI?
I don't think I do understand what you mean. I don't see where there is much code to write
to add knots to a SplineData. Would you mind pointing that out for me?Best,
-Niklas -
On 01/04/2014 at 12:51, xxxxxxxx wrote:
Hi Niklas,
where can I find the source code for the BitmapButtonCustomGui?Originally posted by xxxxxxxx
I don't think I do understand what you mean. I don't see where there is much code to write
to add knots to a SplineData.GeData gdSplineData(CUSTOMDATATYPE_SPLINE, DEFAULTVALUE); //Stores the data gotten from SplineData SplineData *spd = (SplineData* )gdSplineData.GetCustomDataType(CUSTOMDATATYPE_SPLINE); //Creates an instance of the SplineData class if (!spd) return; // spd->SetUserCallback(FooGetUserCallback(3, NULL), NULL); CustomSplineKnot *knot1; //The first spline knot CustomSplineKnot *knot2; //The second spline knot spd->MakeLinearSplineBezier(2); //Real xmin, Real xmax, Real xsteps, Real ymin, Real ymax, Real ysteps spd->SetRange(0.0, 1.0, 0.01, 0.0, 1.0, 0.01); //Set The first spline knot's position to 0,0,0 knot1 = spd->GetKnot(0); knot1->vPos = Vector(0, 0, 0); knot1->lFlagsSettings |= FLAG_KNOT_LOCK_X|ADD_KNOT_ADAPT_TANGENTS; knot1->vTangentRight = Vector(0.2, 0.1, 0); //Set The second spline knot's position to 100,100,0 knot2 = spd->GetKnot(1); knot2->vPos = Vector(1, 1, 0); knot2->lFlagsSettings |= FLAG_KNOT_LOCK_X|ADD_KNOT_ADAPT_TANGENTS; knot2->vTangentLeft = Vector(-0.3, 0.3, 0); Bool success = node->SetParameter(FOO_SPLINE, gdSplineData, DESCFLAGS_SET_0);
Maybe it is the naming convention in C4D that collides with my way of thinking. But I still do not understand how to write my own Custom Data type, and use it the way it is being used for SplineData. I spent many (too many) hours trying to do it myself, but it will always crash at some stage, and not do what SplineData does.
A working example would be just great! Keep it simple! Do not introduce new things that are not strictly necessary to explain things. What also is needed (in my opinion) is an overall description of what the various classes / structures do, what their purposes are, what roles they play and so on. I have read the SDK docs, regarding this. But I did not get much wiser than I was when I started.
-
On 07/04/2014 at 08:33, xxxxxxxx wrote:
Hi Ingvar,
Ok, I see it's quite a few lines of code. But since you say, you do not understand why it is so much
to write, how would you expect such an interface to look like?I tried to keep it as simple as possible, but the example involves 4 classes, 3 of them Cinema 4D
Plugin API subclasses. Custom datatypes and GUIs are one of the most (if not the most) complex
topic regarding plugin implementation in Cinema 4D.You can find the current state of your example on our new GitHub repository for the Cinema4D SDK.
This repository will be filled slowly with better and more understandable examples, examples
for beginners, advanced programmers and experts. The new SDK aims to replace the old one with
greatly improved content in the future. Until then, the two SDKs will co-exist and the current main
one will still be shipped with the Cinema 4D installation.Currently, the example from the repository is still missing that XPresso can read the sub channels
from the custom datatype. I am waiting for a reply from a developer on this.The new SDK project is at its very beginning and there are not even Visual Studio or XCode project
files. The example code is for the Cinema4D R15 API.https://github.com/PluginCafe/cpp-cinema4dsdk/tree/datatype/floatlist/src/datatype
Source:
https://github.com/PluginCafe/cpp-cinema4dsdk/blob/datatype/floatlist/src/datatype/floatlist.cppReadme:
https://github.com/PluginCafe/cpp-cinema4dsdk/blob/datatype/floatlist/src/datatype/floatlist.mdBest,
-Niklas -
On 07/04/2014 at 13:43, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Hi Ingvar,
Ok, I see it's quite a few lines of code. But since you say, you do not understand why it is so much
to write, how would you expect such an interface to look like?Hallo Niklas!
It is not so much the code itself that I have in mind. The code is fine.
I have done object oriented programming for many years. I do accept that in C++ there are no properties, only methods. But I still would expect that the Custom GUI controls would be accessible, so that I could just grab it ans set the knots, just like that.It is this:
GeData gdSplineData(CUSTOMDATATYPE_SPLINE, DEFAULTVALUE); //Stores the data gotten from SplineData SplineData *spd = (SplineData* )gdSplineData.GetCustomDataType(CUSTOMDATATYPE_SPLINE); //Creates an instance of the SplineData class if (!spd) return;
And this:
Bool success = node->SetParameter(FOO_SPLINE, gdSplineData, DESCFLAGS_SET_0);
which I
a) Don't really understand why has to be like this
b) Cannot emulate myself, using my own Custom Data Type classes.
Where b) is my main frustration.All in all:
When programming my C4D plugins, I use one day, where I would have used one hour in, what I would call, normal object oriented SDK. I use one week, instead of one day. etc. etc.It is interesting that a new SDK is on its way!
Having a vibrant and flourishing 3rd party business will strengthen Maxon and Cinema 4D very much.I thank you for the new code, I will look at it as soon as I get the time, and come back with comments! Give me a few days.
-
On 07/04/2014 at 16:59, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Hallo Niklas!
It is not so much the code itself that I have in mind. The code is fine.
I have done object oriented programming for many years. I do accept that in C++ there are no properties, only methods. But I still would expect that the Custom GUI controls would be accessible, so that I could just grab it ans set the knots, just like that.It is this:
GeData gdSplineData(CUSTOMDATATYPE_SPLINE, DEFAULTVALUE); //Stores the data gotten from SplineData SplineData *spd = (SplineData* )gdSplineData.GetCustomDataType(CUSTOMDATATYPE_SPLINE); //Creates an instance of the SplineData class if (!spd) return;
And this:
Bool success = node->SetParameter(FOO_SPLINE, gdSplineData, DESCFLAGS_SET_0);
which I
a) Don't really understand why has to be like this
b) Cannot emulate myself, using my own Custom Data Type classes.
Where b) is my main frustration.All in all:
When programming my C4D plugins, I use one day, where I would have used one hour in, what I would call, normal object oriented SDK. I use one week, instead of one day. etc. etc.I think I understand your point now. Well, the thing is that Cinema 4D does not ship a static
library that plugins can be linked against. That would bring a bunch of limitations and insecurities.
Cinema 4D provides a runtime interface constructed on startup that the Plugin API accesses. Have
you ever taken a look into the resource/_api source files?// c4d_basedraw.cpp void BaseView::GetSafeFrame(Int32* cl, Int32* ct, Int32* cr, Int32* cb) { C4DOS.Bv->GetSafeFrame(this, cl, ct, cr, cb); }
C4DOS.Bv->GetSafeFrame is a function pointer in a structure that is filled by Cinema 4D on startup.
Implementing classes this way is even a little more complicated. The SplineData class is a class
for which the actual implementation is actually hidden in the Cinema 4D application.Another point is that the GeData class does not implement any special value referencing or
counting and is therefore passed by value , not by reference. Copying one GeData to another
will also copy the internal data! This is why you have to get, modify and set the value. Since
you do not hold the real reference of the SplineData that the object uses, you must set the
value back to the parameters.On another note, the comments are not quire right.
// Create the SplineData object. The GeData communicates with Cinema 4D // to find the CustomDataTypeClass implementation for the CUSTOMDATATYPE_SPLINE // plugin and allocate the data ( CustomDataTypeClass::AllocData() ). GeData gdSplineData(CUSTOMDATATYPE_SPLINE, DEFAULTVALUE); // Get the internal SplineData from the GeData object. Here, the Plugin ID is required // to verify, it is for your safety! It'll return NULL when the Plugin ID of the data-type // you want doesn't match the data-type of the actual value in the GeData. SplineData* spd = (SplineData* ) gdSplineData.GetCustomDataType(CUSTOMDATATYPE_SPLINE);
There is also another way to create a SplineData, but it comes with an overhead when setting
the data to the node since the SplineData is 1) copied when calling SetDParameter() to the
GeData and 2) copied to the node when the GeData is actually set in the nodes parameters.SplineData* spd = SplineData::Alloc(); if (spd == nullptr) ... ; // ... node->SetDParameter(SOMESPLINE, GeData(CUSTOMDATATYPE_SPLINE, spd), DESCFLAGS_SET_0);
Originally posted by xxxxxxxx
It is interesting that a new SDK is on its way!
Having a vibrant and flourishing 3rd party business will strengthen Maxon and Cinema 4D very much.I thank you for the new code, I will look at it as soon as I get the time, and come back with comments! Give me a few days.
Yeah, I'm confident that it'll grow very quickly! Don't hesitate to contribute if you have anything
that you want to contribute. We'll just make sure that it applies our new standards for the
SDK (coding style, file headers [description, experience level, tags], etc.). The guidelines will be
added soon.Sure, tell me when there is something you need to understand. That can only help to improve
the example!Best,
-Niklas