SDK Question Dialogue box show grapple points

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
I have a dialogue box. press a key on the box and grapple points are suppose to show. I also have it hard coded with F5
if (key == OAPI_KEY_F5){ // show att points if (oapiGetShowGrapplePoints() == true) oapiSetShowGrapplePoints(false); else oapiSetShowGrapplePoints(true); return 1; }

if the dialogue box:
case IDC_CLOSE: oapiCloseDialog(hWnd); return TRUE; case IDC_GRAPPLE: sts->ToggleGrapple(); return 0; case IDC_SHOWGRAPPLE: oapiSetShowGrapplePoints(SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_GETCHECK, 0, 0) == BST_CHECKED ? true : false); return 0; }

if I press f5 it sometimes turns the grapple points on and I press the button it turns them off but not back on.
I ran the debugger to see if I was hitting the box code and I was.
 

dgatsoulis

ele2png user
Donator
Joined
Dec 2, 2009
Messages
1,927
Reaction score
340
Points
98
Location
Sparta
I was just testing ChatGPT4 on something and I pasted your post in. Here is the response I got:

From your description and the code snippets provided, it looks like there are two different mechanisms controlling the visibility of the grapple points in your application: one via the F5 key and another via a button in a dialog box. If pressing F5 sometimes turns the grapple points on and pressing the button turns them off but not back on, there might be an issue with how the button's state (checked or unchecked) is being managed or how the state is being read in your code.

Let's walk through the possible issues and adjustments:

1. F5 Key Handling

The code for the F5 key appears to correctly toggle the state of the grapple points based on their current state:

Code:
if (key == OAPI_KEY_F5){ // show att points
if (oapiGetShowGrapplePoints() == true) {
oapiSetShowGrapplePoints(false);
} else {
oapiSetShowGrapplePoints(true);
}
return 1;
}

This code checks the current state, toggles it, and seems correct as per your description.

2. Button in Dialog Box

The issue seems to be with how the button state is managed in the dialog box. When you press the button, it should also toggle the state just like the F5 key does. However, it seems the button only sets the state to off and not on again. The likely cause is that the button's checked state is not being updated or not being read correctly when pressed.

Here's the relevant section of your code:

Code:
case IDC_SHOWGRAPPLE:
oapiSetShowGrapplePoints(SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_GETCHECK, 0, 0) == BST_CHECKED ? true : false);
return 0;

Suggested Adjustments​

  1. Ensure the Button is a Check Box
    • Make sure that the button (IDC_SHOWGRAPPLE) is a checkbox. A standard button will not hold a checked or unchecked state, which might be why it does not toggle back on.
  2. Correctly Manage the Check State
    • Ensure that when the button is pressed, it changes its state. This can typically be done by sending BM_SETCHECK message to toggle its state, depending on the current state of the grapple points:

      Code:
      case IDC_SHOWGRAPPLE:
      BOOL isChecked = SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_GETCHECK, 0, 0) == BST_CHECKED;
      SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, isChecked ? BST_UNCHECKED : BST_CHECKED, 0);
      oapiSetShowGrapplePoints(!isChecked);
      return 0;
  3. Synchronize States
    • Ensure that the state of the grapple points is synchronized between the F5 key handling and the button. One way to ensure synchronization is to refresh the checkbox state whenever the dialog is shown or refreshed.

Debugging Further​

  • Check Button Initialization: Verify how the button is initialized. Ensure that its state matches the visibility state of the grapple points when the dialog is opened.
  • Use Debug Logs: Insert logging at key points (e.g., inside the case for IDC_SHOWGRAPPLE and where you handle OAPI_KEY_F5) to log the current state and the action being taken. This will help you understand what the application thinks the state is versus what is actually shown.
By adjusting how the check state is managed and ensuring synchronization between different controls and parts of the application, you should be able to resolve the issue.
I asked it to fix the issue and show the c++ code

ChatGPT
To address the synchronization and state management issues between the F5 key and the checkbox in your dialogue box, I'll provide you with a refined version of your C++ code. This version ensures that the state of the checkbox correctly reflects the visibility of the grapple points and that both mechanisms for toggling (F5 key and checkbox) work harmoniously.

Updated Code:​

1. F5 Key Handling:
  • The F5 key handling appears to be working fine, but let's ensure it explicitly sets the checkbox state if you have access to update the dialog components from this part of your code:
C++:
if (key == OAPI_KEY_F5) { // show att points
bool newGrappleState = !oapiGetShowGrapplePoints();
oapiSetShowGrapplePoints(newGrappleState);

// Assuming you can access the checkbox handle from here:
SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, newGrappleState ? BST_CHECKED : BST_UNCHECKED, 0);

return 1;
}

2. Dialog Box Button Handling:
  • We'll make sure the checkbox toggles its state when clicked and syncs with the actual visibility of the grapple points:
C++:
case IDC_SHOWGRAPPLE: {
// Toggle the checkbox state based on its current state
BOOL isChecked = SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_GETCHECK, 0, 0) == BST_CHECKED;
SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, isChecked ? BST_UNCHECKED : BST_CHECKED, 0);

// Now set the grapple points visibility based on the new checkbox state
oapiSetShowGrapplePoints(!isChecked);
return 0;
}

Important Considerations:​

  • Checkbox Initialization: Ensure the checkbox (IDC_SHOWGRAPPLE) is initialized with the correct state when the dialog is created or shown. This might look something like this:
C++:
// When initializing or showing the dialog:
bool initialGrappleState = oapiGetShowGrapplePoints();
SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, initialGrappleState ? BST_CHECKED : BST_UNCHECKED, 0);
  • Synchronization: If there are other parts of the code where the grapple points' visibility might change (not shown in your snippet), ensure to update the checkbox state accordingly to keep the UI consistent.
  • Debugging: If the issue persists after applying these changes, consider adding logging or breakpoints in both the F5 key handling and checkbox handling code to monitor the actual values of oapiGetShowGrapplePoints() and the checkbox state at runtime.
This code should resolve the toggling issue by ensuring both the F5 key and the checkbox in the dialog box correctly reflect and control the state of the grapple points. Make sure your dialog and other UI components are refreshed appropriately if there are context or scope considerations affecting visibility or state control.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,922
Reaction score
230
Points
138
Location
Cape
Could you use ChatGPT4 to make a .dll for a robotic arm ?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
BOOL CALLBACK RMS_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { GITAI *sts = (uMsg == WM_INITDIALOG ? (GITAI*)lParam : (GITAI*)oapiGetDialogContext(hWnd)); // pointer to vessel instance was passed as dialog context const double step = 0.05*RAD; static double t0; double t1; HICON hIcon; HWND hDlg; bool initialGrappleState = oapiGetShowGrapplePoints(); SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, initialGrappleState ? BST_CHECKED : BST_UNCHECKED, 0);

case IDC_SHOWGRAPPLE: { // Toggle the checkbox state based on its current state BOOL isChecked = SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_GETCHECK, 0, 0) == BST_CHECKED; SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, isChecked ? BST_UNCHECKED : BST_CHECKED, 0); // Now set the grapple points visibility based on the new checkbox state oapiSetShowGrapplePoints(!isChecked); return 0; }

In default graphics the grapple point turn on/off with the F5 and turn on with display but not turn off.
In D3d9 no grapple points display with either

It would nice to see if Chat would make the kinetic code part
 

dgatsoulis

ele2png user
Donator
Joined
Dec 2, 2009
Messages
1,927
Reaction score
340
Points
98
Location
Sparta
Could you use ChatGPT4 to make a .dll for a robotic arm ?

You probably could, but it's not as easy as telling chatGPT "write me a .dll in c++ that controls a robotic arm in Orbiter SpaceFlight Simulator". (althrough, below is the -probably incorrect- answer to that exact prompt).
write me a .dll in c++ that controls a robotic arm in Orbiter SpaceFlight Simulator


ChatGPT
Creating a DLL in C++ for controlling a robotic arm in the Orbiter Space Flight Simulator involves several steps, including setting up a development environment, understanding the Orbiter API, writing the C++ code, and compiling it into a DLL. This example will walk you through the basic framework necessary to get started. Note that actual control logic and integration with Orbiter will require deeper knowledge of the simulator’s API and the specifics of your robotic arm model.

Step 1: Setup Your Development Environment​

You'll need Microsoft Visual Studio to develop a DLL for Orbiter, as Orbiter plugins are typically developed using this IDE on Windows. Ensure you have the Orbiter SDK installed, which provides necessary headers and libraries.

Step 2: Understand the Orbiter API​

Familiarize yourself with the Orbiter API, focusing on how to interact with vessel objects, how to manipulate their states, and how to read input from the simulator environment. The API documentation is crucial here.

Step 3: Write the C++ Code​

Below is a simplified example of what your C++ code might look like. This code sets up a basic DLL structure, including initialization functions and a simple control loop to adjust joint angles. The actual logic will depend on the specific commands you need and how the robotic arm is modeled in Orbiter.

C++:
#include "OrbiterAPI.h"
#include "VesselAPI.h"

class RoboticArm : public VESSEL2 {
public:
RoboticArm(OBJHANDLE hVessel, int flightmodel) : VESSEL2(hVessel, flightmodel) {
}

void clbkSetClassCaps(FILEHANDLE cfg) override {
// Set capabilities, load animations, setup robotic arm parameters
}

void clbkPostStep(double simt, double simdt, double mjd) override {
// Control logic goes here
// For example, adjust joint angles based on some input
}
};

// Entry point that Orbiter calls to instantiate the vessel
DLLCLBK VESSEL* ovcInit(OBJHANDLE hvessel, int flightmodel) {
return new RoboticArm(hvessel, flightmodel);
}

// Cleanup function called by Orbiter
DLLCLBK void ovcExit(VESSEL* vessel) {
if (vessel) delete (RoboticArm*)vessel;
}

extern "C" {
// Required for the DLL to work with Orbiter
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
}

Step 4: Compile the DLL​

  1. Open Visual Studio and create a new project.
  2. Choose a Dynamic-Link Library (DLL) project template.
  3. Add your code to the project.
  4. Configure the project settings to use the Orbiter SDK (include directories, library directories, and additional dependencies).
  5. Build the project to produce the .dll file.

Step 5: Test the DLL in Orbiter​

  1. Place the compiled DLL in the appropriate Orbiter Modules directory.
  2. Run Orbiter and load a scenario where the vessel (robotic arm) is used.
  3. Verify that the arm responds as expected, adjusting the code as necessary.
This is a very basic introduction. Developing for Orbiter or any simulation platform typically requires extensive testing and iteration to handle all possible scenarios and interactions. Be sure to participate in Orbiter forums and communities to get support and feedback on more specific issues.
a possible workflow for a non-programmer such as myself would be this:
1. Get the mesh of the robotic arm and animate it in Vinka's Spacecraft3 (or 4).
2. Take the ini file and use Spacecraft3 to DLL converter 110509, Made by Artlav in 2011. it converts sc3 ini vessels into DLL vessels and C++ source code.
3. Feed the source code to ChatGPT and prompt it to create a more advanced control method for the robotic arm using inverse kinematics. The input from the user would be the selection of the target grapple point and the arm would perform the necessary rotations/translations to reach it. (or return an error code if the grapple point is out of reach)
4. Review and apply the suggestions and code it gives you to the source code from the sc3 to dll converter.
5. Compile and test.
6. Repeat steps 3-5 until it works !?

BOOL CALLBACK RMS_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { GITAI *sts = (uMsg == WM_INITDIALOG ? (GITAI*)lParam : (GITAI*)oapiGetDialogContext(hWnd)); // pointer to vessel instance was passed as dialog context const double step = 0.05*RAD; static double t0; double t1; HICON hIcon; HWND hDlg; bool initialGrappleState = oapiGetShowGrapplePoints(); SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, initialGrappleState ? BST_CHECKED : BST_UNCHECKED, 0);

case IDC_SHOWGRAPPLE: { // Toggle the checkbox state based on its current state BOOL isChecked = SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_GETCHECK, 0, 0) == BST_CHECKED; SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, isChecked ? BST_UNCHECKED : BST_CHECKED, 0); // Now set the grapple points visibility based on the new checkbox state oapiSetShowGrapplePoints(!isChecked); return 0; }

In default graphics the grapple point turn on/off with the F5 and turn on with display but not turn off.
In D3d9 no grapple points display with either

It would nice to see if Chat would make the kinetic code part

I'd take another look at the important considerations section of ChatGPT's reply. Also be aware that ChatGPT doesn't have direct knowledge of Orbiter's API.
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Ok. I can do to basic movement it is the kinetic part that can't get to work.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,922
Reaction score
230
Points
138
Location
Cape
What if you enter the code from say the SSRMS. Could it apply that code to another arm ?
 

dgatsoulis

ele2png user
Donator
Joined
Dec 2, 2009
Messages
1,927
Reaction score
340
Points
98
Location
Sparta
What if you enter the code from say the SSRMS. Could it apply that code to another arm ?
If you have access to the SSRMS code then you can probably apply it to another arm without using chatGPT. (As long as the degrees of freedom are the same, all you need to do is to change the coordinates to apply to the new arm (joint positions, animations, etc).
The code for the SSrms isn't available.
I think I've seen somewhere an old post from Donamy with the SSRMS code attached. -edit: it's here but it seems to be missing the following:
in SSRMS.h
#include "Subsystem.h"
#include "SubsystemDirector.h"
don't exist
in SSRMS.cpp
#include "UltraMath.h"
doesn't exist
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,922
Reaction score
230
Points
138
Location
Cape
The code was available when Siamesecat coded for it while with SSU team. GLS may have it.
 

Gondos

Well-known member
Joined
Apr 18, 2022
Messages
233
Reaction score
272
Points
78
Location
On my chair
I ported it to linux a while ago, the code is here. It should not be too different from the original (except for the GUI which is redone with imgui).
 

Gondos

Well-known member
Joined
Apr 18, 2022
Messages
233
Reaction score
272
Points
78
Location
On my chair
It's a crossplatform GUI library that I used on the linux port since the windows API does not work there. Once the next version of Orbiter is out, I'll see if there's interest in using it on Windows too, if we want to go toward a crossplatform Orbiter. There's already a prototype with the D3D9Client :
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,736
Reaction score
2,707
Points
203
Location
Dallas, TX
Great. So in the SSRMS:
if(ImGui::Button("Toggle grapple points")) { if(!ssrms->ShowAttachmentPoints) { ssrms->ShowAttachmentPoints=true; }else{ ssrms->ShowAttachmentPoints=false; } oapiSetShowGrapplePoints(ssrms->ShowAttachmentPoints); } I have:
case IDC_SHOWGRAPPLE: { // Toggle the checkbox state based on its current state //BOOL isChecked = SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_GETCHECK, 0, 0) == BST_CHECKED; //SendDlgItemMessage(hWnd, IDC_SHOWGRAPPLE, BM_SETCHECK, isChecked ? BST_UNCHECKED : BST_CHECKED, 0); // Now set the grapple points visibility based on the new checkbox state //oapiSetShowGrapplePoints(!isChecked); if (!ShowAttachmentPoints) { ShowAttachmentPoints = true; } else { ShowAttachmentPoints = false; } oapiSetShowGrapplePoints(ShowAttachmentPoints); }
And it works.
 
Top