Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Frequent Contributor
Posts: 116
Registered: ‎10-14-2015
Accepted Solution

Spatial Modeler SDK - How to create an InputPrt which shows a list of strings.

Dear Community,

 

Currently I use an input port which asks for a string. I use the following code (example) :

 

	void
	sm_VectorConvertFormat::Init()
	{
		PortPtr filePort2 = CreatePortWithAttributes(ETXT_TEXT_KEY("OutputFormat"), StringData::GetDataType(),
			SB_PORT_INPUT,
			L"Input", DataFactory::Create<BoolData>(true),
			NULL);

		filePort2->SetDataTypeAttribute<StringData>(StringData::GetDataType(), L"IMAGINE", L"String");

	}

	void
	sm_VectorConvertFormat::OnExecute()
	{
		std::wstring FormatStringIn = GetPort(L"OutputFormat")->GetDataValue<StringData>(L"GeoJSON");

		if (FormatStringIn.empty())
			SetErrorMessage(L"No Output Format specified.");
	}

I would like to use a predefined list of strings, which an user can choose from if he double clicks on the input port. An example of this functionality is shown in the screenshot below. A list of Stings (PixelType's) are shown if an user double clicks on the PixelType input port of the Raster Output Operator.

 

PixelType.png

 

Is there some example code how to do this?

 

Thank you,

Wim

 

 

 

Technical Evangelist
Posts: 53
Registered: ‎09-16-2015

Re: Spatial Modeler SDK - How to create an InputPrt which shows a list of strings.

Wim,

 

You do that with the "AcceptableValues" attribute.  This attribute is recognized by the StringData UIProvider when you double-click on a port and it then gives you the popup list of values to select from.

 

I would change your Init() method to something like

void
sm_VectorConvertFormat::Init()
{
    std::vector<std::wstring> acceptableValues;
    acceptableValues.push_back(L"IMAGINE");
    acceptableValues.push_back(L"GeoJSON");
    PortPtr filePort2 = CreatePortWithAttributes(ETXT_TEXT_KEY("OutputFormat"), StringData::GetDataType(),
SB_PORT_INPUT,
        L"AcceptableValues", DataFactory::Create<StringListData>(acceptableValues),
        NULL);
}

 

Hope this helps!

 

Ruth

 

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.