Is it possible to create a polygon on the fly?

Find and share HowTos to various installations / configurations!
11 posts • Page 1 of 2
iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Is it possible to create a polygon on the fly?

Post by iain »

I have an application where I would like to change the shape of an object or even add a new object in the UI. I've figured out a lot about moving and modifying an object, but what I'd really like to do is to create a polygon given its vertices. Is this possible?

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: Is it possible to create a polygon on the fly?

Post by leoknipp »

With the function addShape() you can add an object to a panel during runtime.
For details please have a look at the WinCC OA Documentation.

Best Regards
Leopold Knipp
Senior Support Specialist

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: Is it possible to create a polygon on the fly?

Post by iain »

Thanks. Which documentation would it be in? I can't find any reference to addShape()

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: Is it possible to create a polygon on the fly?

Post by leoknipp »

You are possibly an older version (<3.16) where the function addShape() does not exist.

Best Regards
Leopold Knipp
Senior Support Specialist

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: Is it possible to create a polygon on the fly?

Post by iain »

I am indeed. I'm working with 3.15. I should have said that. I made it work using the prototype for addShape(), so I guess it's there but undocumented. I have 3.17 in a different environment, so I'll look at that instead.

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: Is it possible to create a polygon on the fly?

Post by iain »

Could I ask a follow-up? Is it possible to add an event to this new polygon? I can create the polygon fine (OA 3.17 now). I've found the function uiConnect() in the documentation, which appears that it's intended to add callbacks to objects. If I'm reading it correctly, it only supports a limited number of events, so maybe "Clicked" isn't one I can use, but even if I use the documented "windowMoved" even I get a "Function not defined" error in the log.

Code: Select all

main()
{
  uiConnect("clicky", "RECT", "windowMoved");
}

clicky(mapping event)
{
  DebugN("event", event);
}
gives function not defined, Line: 3, uiConnect, windowMoved

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: Is it possible to create a polygon on the fly?

Post by leoknipp »

The event "windowMoved" is not an event of an rectangle.
"windowMoved" can be used if not shape is defined, see the example in the WinCC OA Documentation.

Best Regards
Leopold Knipp
Senior Support Specialist

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: Is it possible to create a polygon on the fly?

Post by iain »

The example doesn't help me figure out how to attach an event to a polygon (or rectangle). If the problem is that I'm attempting to attach an invalid event, does that mean there are valid events I can attach to a polygon, or not?

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: Is it possible to create a polygon on the fly?

Post by leoknipp »

Instead of adding a shape you can add a reference during runtime to a panel using the function addSymbol().
To fulfill your requirements you can possibly use the following approach:
-- Create a new reference with the polygon
-- Add the required scripts
-- Load the reference during runtime using addSymbol()
-- Pass the "points" information to the reference using $-parameters (if required)
-- Modify the layout of the polygon in the reference

Best Regards
Leopold Knipp
Senior Support Specialist

iain
Posts:33
Joined: Fri May 19, 2017 7:08 pm

Re: Is it possible to create a polygon on the fly?

Post by iain »

That's actually exactly what I'm planning to do. This particular screen has hundreds of reference panels which each contain other references. I'm planning to replace them with a single reference panel (loaded multiple times with addSymbol()) with a single polygon that I can modify in its init function (I pass vertices in as a string from the owning panel) and which has its own click event. I have simple proof-of-concept code already to check that the click event is handled correctly even with redrawing the polygon and stacking in the order the reference panel is loaded.

I just thought that if I have the data in the parent panel already (probably read from an XML file) then maybe I could create the polys directly - which I can do now, but without events. So if events aren't possible, I will stick with what I'm doing, and your reply validates the approach, which I very much appreciate, since I came across this through experimentation.

Thanks!

11 posts • Page 1 of 2