Enforce unique combination of parameters |
Post Reply |
Author | |
edward22243
Major Contributor Joined: 19.Apr.2019 Points: 41 |
Post Options
Thanks(0)
Posted: 19.Apr.2019 at 13:59 |
I have an object called Cell, and it represents a physical production cell in a 2D-grid (u,v).
The location are paramters u and v and the combination needs to be unique. What does not work is that I set u and v unique individually. After all (1,0) and (1,1) are diffent locations, but they have a common u, namely u=1, so it is not unique. I solved this by defining a location as a string '(u,v)' instead of 2 parameters. But I want to know how I can retrieve u and v from the string '(u,v)' regex (\d+,\d+) or go back to two parameters, but add a check for unique of the combi? Each way is okay for me. |
|
stevek
MetaCase Joined: 11.Mar.2008 Points: 641 |
Answer Post Options Thanks(0) |
If you want UI enforcement of global uniqueness (i.e. trying to enter (1,1) a second time anywhere will be prevented), you can mark that property slot in Cell as Unique. If you want UI enforcement of local uniqueness (i.e. trying to add a second Cell with (1,1) to the same graph will be prevented), you can add a Uniqueness Constraint to the Graph type.
In both cases, you can extract the u and v parameters with a regex translator. I'd drop the parentheses, to save the user having to read and type them all the time, and maybe allow whitespace after the comma:
To make sure the users follow the legal format for Location, you can add a corresponding Regex to the property type, \d+,\s*\d+. (If you want to allow decimals, scientific notation etc., just extend \d as desired.) If on the other hand you want to keep u and v separate, and it's OK just to show an error / warning in the model if values aren't unique, see 6.7.4 Checking instance uniqueness in the Workbench User Guide. If you define an Identifier Generator for the Cell object type, outputting both u and v (e.g. :u ',' :v), those examples should work as-is.
|
|
edward22243
Major Contributor Joined: 19.Apr.2019 Points: 41 |
Post Options
Thanks(0)
|
Hello Steven,
That worked. Was looking through the documentation for regex but could not really fnd it. Had to look for translaters instead, that works good.
|
|
Post Reply | |
Tweet |
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |