Feature interface programming

DSPuzzles
DSPuzzles Member Posts: 17 EDU
I am writing a feature that has a significantly complex interface. This means that the precondition in the feature is a mess. Is there a way to simplify the precondition? Such as loading annotations from another FeatureScript file, for example.
Tagged:

Comments

  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,278 image
    Factoring portions of the precondition into predicates is the best I can suggest -- see for instance how booleanStepScopePredicate (defined in boolean.fs) is used in std.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • DSPuzzles
    DSPuzzles Member Posts: 17 EDU
    This is precisely what I need. Thank you very much!
  • DSPuzzles
    DSPuzzles Member Posts: 17 EDU
    Actually, it's not fixing the problem as I thought it would. Is there a way I can reuse a predicate inside a precondition?

    Because I have an interface that uses a query only in certain places, and I'm using an if statement to decide whether to use it or not. The thing is, the condition becomes a long unreadable mess because it's quite complex. Predicates would solve this if it weren't for the fact that they can only be used once.


  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,278 image
    I see -- you want to avoid copy/pasting the if condition.  Unfortunately, there's no current way to do that...
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • DSPuzzles
    DSPuzzles Member Posts: 17 EDU
    The issue isn't copy-pasting. It's that my if statements look like this: (taken from the actual feature)

    if ((definition.family == familyEnum.CURVED && (definition.curvedSolid == curvedEnum.CYLINDER || definition.curvedSolid == curvedEnum.CONE || definition.curvedSolid == curvedEnum.BICONE)) || (definition.family == familyEnum.POLYGONAL && (definition.polygonalSolid == polygonalEnum.PRISM || ((definition.polygonalSolid == polygonalEnum.PYRAMID || definition.polygonalSolid == polygonalEnum.BIPYRAMID) && definition.heightTypePYR == pyramidHeightEnum.HEIGHT))))
            {
                // Height
                annotation { "Name" : "Height" }
                isLength(definition.height, LENGTH_BOUNDS);
            }

    In fact, here is a link to the featureScript file, since it is a public tool.