cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Translate the entire conversation x

Creo UI Toolkit cannot show image in Drawing Area

ZC_10588822
4-Participant

Creo UI Toolkit cannot show image in Drawing Area

Hi all, I'm using the C++ Object toolkit and the Creo UI editor. I'm developing a plugin for Creo Parametric v10.0.5.0

 

For some reason, I am not able to display an image in the Drawing Area component. 

 

I placed my image in the text directory for the plug-in:

Text -> usascii -> resource -> logo.png

 

Here is my code:

 

 

 

 

#include "pch.h"
#include "DrawingAreaTestDialog.h"

#include <uifcComponent.h>
#include <uifcDrawingArea.h>

Drawing_area_test_dialog::Drawing_area_test_dialog() = default;

void Drawing_area_test_dialog::open_dialog()
{
	if (uifcCreateDialog("DrawingAreaDialog", "DrawingAreaDialog") == 0)
	{
		const uifcDialog_ptr dialog = uifcDialogFind("DrawingAreaDialog", "DrawingAreaDialog");
		Dialog_listener dialog_listener;
		dialog->AddActionListener(&dialog_listener);

		const uifcDrawingArea_ptr drawing_area = uifcDrawingAreaFind("DrawingAreaDialog", "DrawingAreaTest");

		const xstringsequence_ptr image_seq = xstringsequence::create();
		const xstring image = "logo.png";
		image_seq->append(image);

		drawing_area->SetDrawingImageArray(image_seq);
		drawing_area->DrawImage(image_seq->get(0), uifcPoint::Create(10, 10), uifcIMAGE_SELECTED);

		if (uifcActivateDialog("DrawingAreaDialog") == 0)
		{
			uifcExitDialog("DrawingAreaDialog", 0);
			uifcDestroyDialog("DrawingAreaDialog");
		}
	}
}

void Drawing_area_test_dialog::Dialog_listener::OnClose(uifcDialog_ptr handle)
{
	uifcExitDialog("DrawingAreaDialog", 0);
	uifcDestroyDialog("DrawingAreaDialog");
}

 

 

 

 

 

The manual and API docs are not very clear on how to use the Drawing Area component. Am I missing a step in my code? What am I doing wrong?

 

When I run the plugin I see a blank drawing area and no image displayed. See the screenshot attached to view the behavior.

ACCEPTED SOLUTION

Accepted Solutions
VIN
12-Amethyst
12-Amethyst
(To:ZC_10588822)

Hi,in creo toolkit can use api ProUIDialogPostmanagenotifyActionSet
Set the load picture in drawing area function to be called when a dialog has just been managed.

View solution in original post

3 REPLIES 3
VIN
12-Amethyst
12-Amethyst
(To:ZC_10588822)

Hi,in creo toolkit can use api ProUIDialogPostmanagenotifyActionSet
Set the load picture in drawing area function to be called when a dialog has just been managed.

ZC_10588822
4-Participant
(To:VIN)

Hi VIN,

 

Thanks for the response! I am setting the image before the dialog is shown. The dialog is shown when uifcActivateDialog method is called. Searching I found this article on how to use a drawing area via protoolkit: https://www.ptc.com/en/support/article/CS202469

 

It does not use ProUIDialogPostmanagenotifyActionSet but I'm also having trouble getting this example code to display the image. I'll try your suggestion and report back.

Thanks @VIN for the clue. Since, I'm using the OTK I implemented this event OnDisplay it seems like I must do that to load the image into the Drawing Area component properly. 

 

Here is my updated code:

#include "pch.h"
#include "DrawingAreaTestDialog.h"

#include <uifcComponent.h>
#include <uifcDrawingArea.h>

Drawing_area_test_dialog::Drawing_area_test_dialog(const std::string& image_path)
{
	_image_path = image_path;
}

void Drawing_area_test_dialog::open_dialog()
{
	if (uifcCreateDialog("DrawingAreaDialog", "DrawingAreaDialog") == 0)
	{
		const uifcDialog_ptr dialog = uifcDialogFind("DrawingAreaDialog", "DrawingAreaDialog");
		Dialog_listener dialog_listener(*this);
		dialog->AddActionListener(&dialog_listener);

		if (uifcActivateDialog("DrawingAreaDialog") == 0)
		{
			uifcExitDialog("DrawingAreaDialog", 0);
			uifcDestroyDialog("DrawingAreaDialog");
		}
	}
}

Drawing_area_test_dialog::Dialog_listener::Dialog_listener(Drawing_area_test_dialog& dialog) : _dialog(dialog)
{
}

/// <summary>
/// When this event is triggered then we need to select the image to display
/// in the drawing area component.
/// </summary>
/// <param name="handle">Handle to the dialog object</param>
void Drawing_area_test_dialog::Dialog_listener::OnDisplay(uifcDialog_ptr handle)
{
	const xstringsequence_ptr image_seq = xstringsequence::create();
	const char* current_image_path = _dialog._image_path.c_str();
	image_seq->append(current_image_path);

	const uifcDrawingArea_ptr drawing_area = uifcDrawingAreaFind("DrawingAreaDialog", "DrawingAreaTest");
	const uifcDimension_ptr image_dimensions = drawing_area->GetImageSize(current_image_path);
	drawing_area->SetWidth(image_dimensions->GetWidth());
	drawing_area->SetHeight(image_dimensions->GetHeight());
	drawing_area->SetDrawingImageArray(image_seq);
	drawing_area->DrawImage(image_seq->get(0), uifcPoint::Create(0, 0), uifcImageFlags_nil);
}

/// <summary>
/// This event is triggered when a user resizes the dialog.
/// When the dialog is resized the Drawing Area component is cleared.
/// We need to redraw the image in the Drawing Area component.
/// </summary>
/// <param name="handle">Handle to the dialog object</param>
void Drawing_area_test_dialog::Dialog_listener::OnSize(uifcDialog_ptr handle)
{
	const xstringsequence_ptr image_seq = xstringsequence::create();
	const char* current_image_path = _dialog._image_path.c_str();
	image_seq->append(current_image_path);

	const uifcDrawingArea_ptr drawing_area = uifcDrawingAreaFind("DrawingAreaDialog", "DrawingAreaTest");
	const uifcDimension_ptr image_dimensions = drawing_area->GetImageSize(current_image_path);
	drawing_area->SetDrawingImageArray(image_seq);
	drawing_area->DrawImage(image_seq->get(0), uifcPoint::Create(0, 0), uifcImageFlags_nil);
}

void Drawing_area_test_dialog::Dialog_listener::OnClose(uifcDialog_ptr handle)
{
	uifcExitDialog("DrawingAreaDialog", 0);
	uifcDestroyDialog("DrawingAreaDialog");
}

 

Announcements

Top Tags