Your Altium Design Software's PCB Editor is a rules-driven environment. Design requirements are enforced through a well-defined set of Design Rules, which collectively define the constraints for the board. Design rules target specific objects within a design. For the PCB rules system to know for which objects a given rule applies, it needs to know the scope of that rule - the extent of its application. Scoping, or targeting the rule, is performed in the PCB Rules and Constraints Editor dialog.
Rather than being restricted to a predefined list of possible target options, each design rule is scoped by writing what is called a Query. A query is essentially an instruction to the software that defines the set of design objects to be targeted. Queries are written using query keywords. In the same way that a query can be written in a Filter panel to find a specific set of objects, so too a query is written to define the objects that each rule targets. An example might be:
InNet('VBAT') And OnLayer('Bottom Layer')
If this query were to be used as the scope for a Width rule, whenever you route the VBAT net and switch to the bottom layer, the track width would automatically change to the width specified as part of that rule's constraints. Also, upon running a design rule check, any VBAT net routing on the bottom layer would have to have the specified width or it would be flagged as a violation.
Simple scoping options are provided that allow you to quickly generate scope queries. Select one of the options from the first drop-down field and, if required, use the subsequent drop-down list(s) to select the appropriate target, such as a Net, Layer, Footprint, Package, and so on. The scoping options presented are focused according to rule type.
The Custom Query option enables you to write your own, maybe more complex, but also more specific query. You can type your own specific query for the rule scope directly into the query region to the right. Alternatively, two features are available to help in the creation of logical query expressions - the Query Builder and the Query Helper. These can be very useful when unsure of the syntax of a query, or the possible keywords available for use.
Click the button to open the Building Query from Board dialog, which enables you to create a query for targeting specific objects in the design document by simple construction of a string of conditional statements.
The left-hand section of the dialog is used to specify the condition(s) required to target the set of objects needed. Each condition is made up of a Condition Type and a Condition Value. Drop-down fields for these populate with entries that are relevant to building a scope for the current rule type and values for the chosen condition type, respectively.
As a condition is defined, a preview of the currently built query is shown in the right-hand section of the dialog. Conditions can be ANDed and/or ORed together, and also precedence incorporated (through the use of brackets/indenting) to refine the target set of objects. When the expression for the query has been defined as required, clicking OK will load the expression into the query region of the PCB Rules and Constraints Editor dialog.
With the Custom Query option enabled, click the button to access the Query Helper dialog. The underlying Query Engine analyzes the PCB design and lists all available objects, along with generic keywords for use in queries.
Working with the Query Helper is fairly intuitive, even more-so when you break it down into three distinct areas, as illustrated in the image below:
These areas are:
Use the button (bottom-left of the dialog) to verify that an expression is syntactically correct. When the expression for the query has been defined as required, clicking OK will load the expression into the query region of the PCB Rules and Constraints Editor dialog.
Before leaving this area, it is worthwhile taking a look at the order of precedence in place for the operators used in logical Query expressions. After all, without such knowledge, an expression may not target the objects required.
Brackets have the highest precedence within an order of precedence that has been defined for the various operators, and which determines how queries are interpreted by the software (whenever the user has not provided brackets). The sequence of this order, from highest to lowest, is as follows:
Since a design rule is scoped to apply to a target set of design objects, it can be easier (and faster) to first identify those objects then create a design rule that targets them. The PCB Filter panel provides the facility for creating a design rule, the scope of which uses the currently defined query expression in the panel. So rather than struggling to visualize what your query expression might target, use the PCB Filter panel to test and tweak a query expression until only those required objects are filtered. By then creating a rule that uses that query expression, you are guaranteed to be targeting the correct set of objects.
To add a new design rule:
Over time, a number of useful query expressions will be constructed in the course of laying out various boards. Typically, you will want to apply and re-apply the same queries, not only in the same design but across different designs. To cater for this, the PCB Filter panel supports the notion of Historical and Favorite queries.
As a query is entered and applied from the panel, it will be added to a query 'history list'. In addition, that query can be added to a query 'favorites list' by clicking the Add To Favorites button. Use the History and Favorites buttons in the panel to access the corresponding tabs of the same name within the Expression Manager dialog to see these lists.
To use an expression in either list, double-click on its entry or select its entry and click the Apply Expression button. The Expression Manager dialog will close and the expression will be loaded into the Filter region of the PCB Filter panel.
This functionality streamlines (and expedites) creation of rules with requisite scoping - retrieve an historical or favorite query expression, check that it still targets the required object set (apply the filter) then create a rule that utilizes that expression in its scoping, as detailed in the previous section.
Depending on the board design, a fair number of design rules may need to be defined with scopes that range from the very simple to the very complex. It is a good idea to check that the rules defined do indeed target their intended objects. Care at the rule definition stage can save wasted time and effort tracing violations caused through incorrect rule scoping.
The PCB Rules and Constraints Editor dialog includes a query testing facility, allowing you to quickly see what objects a particular rule applies to. Click the button at the top-right of the main editing window for the rule you want to test. The Test Queries Result dialog will appear. This dialog reflects the number of objects falling under the scope of the expression, how many are applicable to the current rule, and how many are applicable based on the rule's current priority (where multiple applicable rules exist). By clicking on a link to the right, you can quickly filter to see the applicable objects in each case directly in the workspace.
You can also quickly see what objects a particular rule applies to from the PCB Rules And Violations panel. The panel lists all currently defined rules for the design. All rules can be viewed or you can browse specifically by rule type - provided at least one rule of any given type has been defined for the active design. As you click on a specific rule in the Rules region of the panel, filtering will be applied using the rule as the scope of the filter. Only those design objects that fall under the scope of the rule will be filtered. By employing the Mask (or Dim) highlighting feature, you can quickly see the resulting objects targeted by the rule.
Using the PCB Rules And Violations panel to interrogate which objects a rule applies to is particularly useful when creating a query for a rule’s scope(s) since a rule can be edited directly from the panel and therefore, the query can be 'tweaked' until the desired objects are captured by the scope(s).
To edit the scope(s) for a rule as well as its constraints, either double-click on the rule's entry in the panel or right-click and choose Properties from the context menu. The relevant Edit PCB Rule dialog will appear from where the changes can be made.