Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » How to edit myHelloWorld class code from example in C/C++ editor?
How to edit myHelloWorld class code from example in C/C++ editor? [message #1834724] Mon, 16 November 2020 21:21 Go to next message
Manuel Malagon is currently offline Manuel MalagonFriend
Messages: 49
Registered: December 2011
Member
I'm following the Hello World example found in https://wiki.eclipse.org/Papyrus/Codegen/CppHelloWorld and I'd like to know if there is a way of editing code in the C/C++ text editor instead of the hideous "body" text box in the "Profile" section of "myMainClass".

I can't insert code using that "body" box. It doesn't let me press enter so I can only write:
int main (int argc, char* argv[])

And I can't see any right-click option for using the C/C++ text editor to enter the code for main. Is there a way of doing this?

Also, that makes me wonder how that code in the example was put there in the first place.
Re: How to edit myHelloWorld class code from example in C/C++ editor? [message #1834874 is a reply to message #1834724] Thu, 19 November 2020 13:29 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 281
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Hi,

there are two ways to enter code into the model


  1. Use the Papyrus C/C++ view. Windows->Show view->Other, select Papyrus-C/C++. Please note that this view is deprecated.

  2. Newer versions of Papyrus designer provide a C/C++ tab in the property view that allows to edit the attributes of the C/C++ profile with a suitable widget. Please download a nightly build , e.g. for 2020-06 or 2020-12, see https://ci.eclipse.org/papyrus/view/Designer/ for instance the update site https://ci.eclipse.org/papyrus/job/papyrus-designer-2020-06/lastSuccessfulBuild/artifact/releng/org.eclipse.papyrus.designer.p2/target/repository/

  3. Open a synchronizing Papyrus CDT editor. In order to do so, right click on the class and choose Designer->open a CDT editor from the context menu. It's a good idea to drag the CDT window to the right, so that you can edit model and code simultaneously. Whenever you change the focus, the synchronization is done. Please note that this open is primarily for "normal" methods that have a corresponding opaque behavior in the model. I just tested that the stereotype's body attribute gets correctly updated but an opaque behavior for main gets created in addition which should not be the case.

Re: How to edit myHelloWorld class code from example in C/C++ editor? [message #1834896 is a reply to message #1834874] Fri, 20 November 2020 01:49 Go to previous messageGo to next message
Manuel Malagon is currently offline Manuel MalagonFriend
Messages: 49
Registered: December 2011
Member
Thank you very much for helping!

Ansgar Radermacher wrote on Thu, 19 November 2020 08:29

Open a synchronizing Papyrus CDT editor. In order to do so, right click on the class and choose Designer->open a CDT editor from the context menu.


I'm on the papyrus perspective and when I execute that what you say no other window is opened. Actually, nothing seems to happen.

When I right-click on the class and choose Designer->open a CDT editor from the context menu I get a popup box asking to select a code generator. It has two options, Standard C and Standard C++, and nothing happens regardless of what I select.

Do you know what this could be?

[Updated on: Fri, 20 November 2020 03:06]

Report message to a moderator

Re: How to edit myHelloWorld class code from example in C/C++ editor? [message #1834919 is a reply to message #1834896] Fri, 20 November 2020 14:16 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 281
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Did you use a nightly build of Designer? (probably yes, since you had the option to generate C code which is not part of the build). Which Eclipse version?

The C/C++ view appears in the same area where the property view is, it can easily be overlooked.

Assuming that you used a nightly build: did you see the C/C++ tab in the property view when you select a class already having the "Include" stereotype? The appearance of the tab depends on the selected element and is currently only supported for some elements already having the stereotype (such as "Include").

Concerning the CDT integration. The idea is that the tool generates code and then opening the editor on the generated code. In order to do so, it needs to know which generator to use, as both the C and C++ generator are eligible for models applying the C/C++ profile. Therefore, the tool uses a hint (in form of a stereotype of a common code-generation profile) in order to store the generator choice. If the hint is not present, the popup is invoked. Normally, you should choose Standard C++ (you'll be asked only once) and a CDT editor should open. As this is apparently not the case, can you please observe the error-log for eventual exceptions (empty the log before invoking the CDT editor).
Re: How to edit myHelloWorld class code from example in C/C++ editor? [message #1834924 is a reply to message #1834919] Fri, 20 November 2020 17:49 Go to previous messageGo to next message
Manuel Malagon is currently offline Manuel MalagonFriend
Messages: 49
Registered: December 2011
Member
Ansgar Radermacher wrote on Fri, 20 November 2020 09:16
Did you use a nightly build of Designer? (probably yes, since you had the option to generate C code which is not part of the build). Which Eclipse version?


Version: 2020-09 (4.17.0)


Ansgar Radermacher wrote on Fri, 20 November 2020 09:16
The C/C++ view appears in the same area where the property view is, it can easily be overlooked.

Assuming that you used a nightly build: did you see the C/C++ tab in the property view when you select a class already having the "Include" stereotype? The appearance of the tab depends on the selected element and is currently only supported for some elements already having the stereotype (such as "Include").


Yes, I can see the C/C++ tab showing up when selecting a class with the <<Include>> stereotype.


Ansgar Radermacher wrote on Fri, 20 November 2020 09:16
Concerning the CDT integration. The idea is that the tool generates code and then opening the editor on the generated code. In order to do so, it needs to know which generator to use, as both the C and C++ generator are eligible for models applying the C/C++ profile. Therefore, the tool uses a hint (in form of a stereotype of a common code-generation profile) in order to store the generator choice. If the hint is not present, the popup is invoked. Normally, you should choose Standard C++ (you'll be asked only once) and a CDT editor should open. As this is apparently not the case, can you please observe the error-log for eventual exceptions (empty the log before invoking the CDT editor).


Well, now that you mention this. in order to use CDT editor I had to generate the code first which in turn creates a CDT project. After generating the CDT project, right-clicking on the class and selecting Designer and Open a CDT Editor causes the C/C++ editor to open the CDT project cpp file created by the code generation step.

But I thought that when creating a diagram I could edit code using the normal C/C++ editor within the papyrus project, without having to create the CDT project first, and not using the C/C++ tab. The tab is fine for a couple of lines of code, but as code grows that becomes a big problem, especially with the plain text editing and lack of code navigation in the tab that the C/C++ CDT editor provides.

[Updated on: Fri, 20 November 2020 18:38]

Report message to a moderator

Re: How to edit myHelloWorld class code from example in C/C++ editor? [message #1834989 is a reply to message #1834924] Mon, 23 November 2020 07:42 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 281
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Hi,

> But I thought that when creating a diagram I could edit code using the normal C/C++ editor within the papyrus project, without having to create the CDT project first, and not using the C/C++ tab. The tab is fine for a couple of lines of code, but as code grows that becomes a big problem, especially with the plain text editing and lack of code navigation in the tab that the C/C++ CDT editor provides.

when I said that you have to generate code first, I described what happens internally. The end user should not have to care about it. However, the project into which the generated code will be stored, needs to exist. This is a bug, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=569052 (as the project already existed in my tests, I did not notice that). It will be corrected as soon as possible.

But code synchronization should work, see how it's done for the Robotics customization in this video: https://www.youtube.com/watch?v=P61COtOuUm0 (even if used in a different context, the approach is based on the same synchronizing CDT editor as in base SW designer)
Re: How to edit myHelloWorld class code from example in C/C++ editor? [message #1835036 is a reply to message #1834989] Mon, 23 November 2020 18:35 Go to previous messageGo to next message
Manuel Malagon is currently offline Manuel MalagonFriend
Messages: 49
Registered: December 2011
Member
Thanks for answering, so far so good.

But there is a problem. I don't know if it has to do with my issue but I can see in the video that the example is using a component diagram and using an activity with what it seems to be the << Function>> stereotype. I get what you say that it is essentially the same but the elements in the diagram are totally different since I'm using a class diagram and there is no << Function>> stereotype to assign to OpaqueBehaviors.

I mention this because synchronization is not working for me when I edit the code in the CDT project.

When I edit the code in the UML tab for the OpaqueBehavior it works very well. I can see how the code is updated in the C/C++ editor for the .cpp file in the CDT project as soon as I save the papyrus change.
index.php/fa/39397/0/

But it is not working the other way around when I make a change in the .cpp file with the C/C++ editor in the CDT project. Nothing happens even when I make the change and then save the cpp file.
index.php/fa/39398/0/

Do I have to explicitly run anything? I don't think so since this seems to be happening automatically in the video.

I don't know if I'm missing something. I attach my papyrus project for you to verify this. I feel there is something I'm missing.

[Updated on: Mon, 23 November 2020 18:38]

Report message to a moderator

Re: How to edit myHelloWorld class code from example in C/C++ editor? [message #1835144 is a reply to message #1835036] Wed, 25 November 2020 15:30 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 281
Registered: March 2011
Location: Paris Saclay, France
Senior Member
It seems that you did not open a synchronizing editor, but a "normal" CDT editor. The synchronizing editor has a green bar on the left, if synchronization is active (it will turn orange, if you close for instance the model).
Do not open the CDT editor on the generated file using the project or package editor, use the context menu in the model to open the editor.
Re: How to edit myHelloWorld class code from example in C/C++ editor? [message #1835152 is a reply to message #1835144] Wed, 25 November 2020 18:43 Go to previous message
Manuel Malagon is currently offline Manuel MalagonFriend
Messages: 49
Registered: December 2011
Member
Ansgar Radermacher wrote on Wed, 25 November 2020 10:30
It seems that you did not open a synchronizing editor, but a "normal" CDT editor. The synchronizing editor has a green bar on the left, if synchronization is active (it will turn orange, if you close for instance the model).
Do not open the CDT editor on the generated file using the project or package editor, use the context menu in the model to open the editor.


Awesome!! That did the trick!

You are right, I opened the file directly from the CDT project, but if I use the context menu then it synchronizes well.
Previous Topic:StringMatcher error
Next Topic:Bug? Empty Comments and non-existent return values being autogenerated
Goto Forum:
  


Current Time: Mon Jan 18 17:53:29 GMT 2021

Powered by FUDForum. Page generated in 0.02181 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top