Quantcast
Channel: Mentor Graphics Communities: Message List
Viewing all articles
Browse latest Browse all 1329

Re: Selecting an object in an area

$
0
0

Your task is a bit complicated.  There is some logic involved, and no quick and dirty answer that immediately gives you what you want.  Several things apply:

 

1. The polygon are of interest may not be rectangular.  It may be L shaped or U shaped, meaning that there are points inside the extrema which are not inside the polygon.

 

2. Some other polygon, such as the route obstruct you are looking for, may cross the polygon of interest but have no points inside it.  Stepping through the list of coordinates of the route obstruct may not tell you that the polygons cross each other. To know for certain that two polygons cross each other, the test which asks "Is point X inside polygon A?" has to be done both ways.  See if any points from polygon A are inside polygon B, and then if any points from polygon B are inside polygon A. If the polygons are crossing each other, one of the two cases must be true.

 

3. Even though the number of route obstructs on a board is probably not a large number, you would probably prefer to not loop through all of them.  Also, because of 1 and 2 above, the loop would have to be done twice.  So let's try to do as little computing as possible, so as to not unduly inconvenience the electrons we have available.

 

Here's how I'd do it:

 

1. Get the extrema of the polygon from the IDF.  If you can get those points into an array, you can use something like this to find the extrema:

 

Dim n, i AsInteger

         Dim ary(,) AsDouble

         Dim minx, miny, maxx, maxy AsDouble

         'x and y are the first element; 0 for x, 1 for y, the 2nd element is the value of the x or y

        

         minx = 10000000000

         miny = 10000000000

         maxx = -10000000000

         maxy = -10000000000

         'these numbers are meaningless, just arbitrarily large; much larger than your expected coordinate range values

        

         ary = get_your_points_from_idf()

         For n = 0 To UBound(ary, 2)    'ubound(ary, 2) gets the range of the 2nd element of the array

             If ary(0, n) < minx Then minx = ary(0, n)

             If ary(0, n) > maxx Then maxx = ary(0, n)

             If ary(1, n) < miny Then miny = ary(1, n)

             If ary(1, n) > maxy Then maxy = ary(1, n)

         Next

        

'the min and max value now represent the extrema of the points in the array.

 

If you have the points in some other format or object, you'll have to come up with a way to loop through it and do the same kind of comparison to find the min and max points.

 

2. With the extrema from step 1, use the Pick function to find any route obstructs that either cross or are inside the extrema.  This narrows down the collection of route obstructs to evaluate. You can add them to an arraylist or MGCPCB.Obstructs collection to hold them for later use.  (hint - the arraylist is easier to work with and will do the job just fine)

 

3. Now that you have a small number of possible route obstructs to work with, you can afford to be more precise.

 

4. Use the IDF polygon to draw an object on a userlayer.

 

5. Get the geometry of this object (userlayergfx.geometry). Let's call it idfgeom.

 

6 . Get the pointsarray of the idfgeom (idfgeom.pointsarray)

 

7. Loop through the collection of obstructs you got earlier.

 

8. For each obstruct,

     - get the geometry and pointsarray.

     - loop through the points in the obstruct pointsarray

          - use the geometry.IsPointEnclosed function to see if the point is inside the idfgeom

     - if no points from the obstruct are inside the idfgeom, do the comparison the other way.  Loop through the idfgeom's pointsarray and see if any of the points are inside the geometry of the objstruct.

 

I think that covers the majority of it.  You will need to read the help documentation to see how to use some of these functions; they are all in there. Be sure to read the part about using pointsarrays, and keep in mind that pointsarrays are always declared as datatype Object.

 

If you get stuck at some point, don't hesitate to ask more questions.


Viewing all articles
Browse latest Browse all 1329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>