; From Abgen Rules (IO Team)
; Modification in link with IOLIB_80 HCMOS7 qualification.
;
; 24/11/98 P.Rouart	- Try to comment all viaPorts commands...
; 01/12/98 P.Rouart	- Add comments.
; 06/03/99 P.Rouart	- Modify bkgnd : size of vxObs > prBoundary



;-----------------------------------------
;    Recovery of each metal and via shapes 
;-----------------------------------------
;abgenRules((bkgnd = geomBkgnd()) 
abgenRules((bkgnd = geomOr("prBoundary")) 
    (metal1 = geomOr("metal1")) 
    (metal1 = geomAndNot(metal1 "y1")) 
    (metal2 = geomOr("metal2")) 
    (metal2 = geomAndNot(metal2 "y2")) 
    (metal3 = geomOr("metal3"))
    (metal3 = geomAndNot(metal3 "y3")) 
    (metal4 = geomOr("metal4")) 
    (metal4 = geomAndNot(metal4 "y4")) 
    (metal5 = geomOr("metal5")) 
    (metal5 = geomAndNot(metal5 "y5")) 
;    (metal6 = geomOr("metal6")) 
;    (metal6 = geomAndNot(metal6 "y6")) 
    (via1 = geomOr("v1")) 
    (via1 = geomAndNot(via1 via1)) 
    (via2 = geomOr("v2")) 
    (via2 = geomAndNot(via2 via2)) 
    (via3 = geomOr("v3"))
    (via3 = geomAndNot(via3 via3)) 
    (via4 = geomOr("v4")) 
    (via4 = geomAndNot(via4 via4)) 
;    (via5 = geomOr("v5")) 
;    (via5 = geomAndNot(via5 via5)) 


;-----------------------------------------------------------
;    Make strong connections between pins maybe not connected in 
;    the layout...
;	This MUST be updated according to the IOLIB.
;-----------------------------------------------------------

 joinableNet("VPLUS" "VMINUS" "VMINUS1" "vdd!" "gnd!" "gndsub!" "vdd3!" "|vdd!" "|gnd!" "||vdd!"
	"||gnd!" "|||vdd!" "|||gnd!" "||||vdd!" "||||gnd!"
	"VDDCORE" "IO" "VSSCORE"
	"ASRC0!" "ASRC1!" "ASRC2!" "ASRC3!" "ASRC4!" "ASRC5!" "ASRC6!"
	"m3gnda!" "m3gndb!" "m3gndc!" "m3gndd!"
	"m3vdda!" "m3vddb!" "m3vddc!"
	"m3vdd3a!" "m3vdd3b!" "m3vdd3c!" "m3vdd3d!"
	"m3gndsa!" "m3gndsb!" "m3gndsc!"
	"m3vdd5a!"
	"m4gnda!" "m4gndb!" "m4gndc!" "m4gndd!" "m4gnde!"
	"m4vdda!" "m4vddb!" "m4vddc!"
	"m4vdd3a!" "m4vdd3b!" "m4vdd3c!"
	"m4gndsa!" "m4gndsb!"
	"m4vdd5a!"
	"m5gnda!" "m5gndb!" "m5gndc!" "m5gndd!"
	"m5vdda!" "m5vddb!" "m5vddc!"
	"m5vdd3a!" "m5vdd3b!" "m5vdd3c!"
	"m5gndsa!" "m5gndsb!" "m5gndsc!"
	"m5vdd5a!"
    )

;---------------------------------------------------------
;   Make connections between via and corresponding metals.
;---------------------------------------------------------
    geomConnect(
	(via via1 metal1 metal2) 
	(via via2 metal2 metal3) 
	(via via3 metal3 metal4) 
	(via via4 metal4 metal5)
    ) 
;(via via5 metal5 metal6)

;--------------------------------------------------------------
;   Recovery of metals by purpose : Pmetalx  <=> purpose pin
;				   Bmetalx <=> boundary purpose.
;	on all hierarchy.
;--------------------------------------------------------------
    (Pmetal1 = geomOr(geomGetPurpose("metal1" "pin" 0 20))) 
    (Bmetal1 = geomOr(geomGetPurpose("metal1" "boundary" 0 20))) 
    (Pmetal2 = geomOr(geomGetPurpose("metal2" "pin" 0 20))) 
    (Bmetal2 = geomOr(geomGetPurpose("metal2" "boundary" 0 20)))
    (Pmetal3 = geomOr(geomGetPurpose("metal3" "pin" 0 20))) 
    (Bmetal3 = geomOr(geomGetPurpose("metal3" "boundary" 0 20))) 
    (Pmetal4 = geomOr(geomGetPurpose("metal4" "pin" 0 20))) 
    (Bmetal4 = geomOr(geomGetPurpose("metal4" "boundary" 0 20))) 
    (Pmetal5 = geomOr(geomGetPurpose("metal5" "pin" 0 20)))
    (Bmetal5 = geomOr(geomGetPurpose("metal5" "boundary" 0 20))) 
;    (Pmetal6 = geomOr(geomGetPurpose("metal6" "pin" 0 20)))
;    (Bmetal6 = geomOr(geomGetPurpose("metal6" "boundary" 0 20))) 

;-------------------
;   Recovery of pins.
;-------------------
    ; Get all shapes connected to pins on one layer level.
    (m1Pins = geomOr(getAllPinShapes(metal1)))
    (m2Pins = geomOr(getAllPinShapes(metal2))) 
    (m3Pins = geomOr(getAllPinShapes(metal3))) 
    (m4Pins = geomOr(getAllPinShapes(metal4))) 
    (m5Pins = geomOr(getAllPinShapes(metal5)))
;    (m6Pins = geomOr(getAllPinShapes(metal6)))

    ; Get shapes in metalx overlapping pin metalx.
    (Pmetal1 = geomAnd(Pmetal1 m1Pins)) 
    (Pmetal2 = geomAnd(Pmetal2 m2Pins)) 
    (Pmetal3 = geomAnd(Pmetal3 m3Pins)) 
    (Pmetal4 = geomAnd(Pmetal4 m4Pins))
    (Pmetal5 = geomAnd(Pmetal5 m5Pins)) 
;    (Pmetal6 = geomAnd(Pmetal6 m6Pins)) 

    ;  ????? Seems to be redondant with precedent step.
    (allPmetal1 = geomOverlap(m1Pins Pmetal1)) 
    (allPmetal2 = geomOverlap(m2Pins Pmetal2)) 
    (allPmetal3 = geomOverlap(m3Pins Pmetal3)) 
    (allPmetal4 = geomOverlap(m4Pins Pmetal4)) 
    (allPmetal5 = geomOverlap(m5Pins Pmetal5))
;    (allPmetal6 = geomOverlap(m6Pins Pmetal6))

    ; add to metalx shapes the shapes connected to ajacent layers.
    for(i 1 30 
	(allPmetal2 = geomOr(allPmetal2 
		geomOverlap(m2Pins 
		    geomAnd(allPmetal1 via1)
		) 
		geomOverlap(m2Pins 
		    geomAnd(allPmetal3 via2)
		)
	    )) 
	(allPmetal3 = geomOr(allPmetal3 
		geomOverlap(m3Pins 
		    geomAnd(allPmetal2 via2)
		) 
		geomOverlap(m3Pins 
		    geomAnd(allPmetal4 via3)
		)
	    ))
	(allPmetal4 = geomOr(allPmetal4 
		geomOverlap(m4Pins 
		    geomAnd(allPmetal3 via3)
		) 
		geomOverlap(m4Pins 
		    geomAnd(allPmetal5 via4)
		)
	    ))
	(allPmetal5 = geomOr(allPmetal5 
		geomOverlap(m5Pins 
		    geomAnd(allPmetal4 via4)
		)
	    )) 
	(allPmetal1 = geomOr(allPmetal1 
		geomOverlap(m1Pins 
		    geomAnd(allPmetal2 via1)
		)
	    ))
    ) 

    (m1Pins = geomOutside(m1Pins allPmetal1)) 
    (m2Pins = geomOutside(m2Pins allPmetal2)) 
    (m3Pins = geomOutside(m3Pins allPmetal3)) 
    (m4Pins = geomOutside(m4Pins allPmetal4))
    (m5Pins = geomOutside(m5Pins allPmetal5)) 
;    (m6Pins = geomOutside(m6Pins allPmetal6)) 

;-----------------------------
;From Pins to Ports.
;	geomNoHoles : fill the holes.
;	geomStamp : get the connectivity.
;	saveInterconnect : copy the shapes into the extracted view.
;		(with net purpose if connectivity exists).		
;-----------------------------

    (m1Ports = geomOr(m1Pins Pmetal1)) 
    (m1Ports = geomNoHoles(m1Ports)) 
    (m1Ports = geomStamp(m1Ports metal1)) 
    (m2Ports = geomOr(m2Pins Pmetal2))
    (m2Ports = geomNoHoles(m2Ports)) 
    (m2Ports = geomStamp(m2Ports metal2)) 
    (m3Ports = geomOr(m3Pins Pmetal3)) 
    (m3Ports = geomNoHoles(m3Ports)) 
    (m3Ports = geomStamp(m3Ports metal3))
    (m4Ports = geomOr(m4Pins Pmetal4)) 
    (m4Ports = geomNoHoles(m4Ports)) 
    (m4Ports = geomStamp(m4Ports metal4)) 
    (m5Ports = geomOr(m5Pins Pmetal5)) 
    (m5Ports = geomNoHoles(m5Ports))
    (m5Ports = geomStamp(m5Ports metal5)) 
;    (m6Ports = geomOr(m6Pins Pmetal6)) 
;   (m6Ports = geomNoHoles(m6Ports))
;    (m6Ports = geomStamp(m6Ports metal6)) 
    saveInterconnect((m1Ports "metal1")) 
    saveInterconnect((m2Ports "metal2"))
    saveInterconnect((m3Ports "metal3")) 
    saveInterconnect((m4Ports "metal4")) 
    saveInterconnect((m5Ports "metal5")) 
;    saveInterconnect((m6Ports "metal6")) 


;---------------------------------------
; Recovery and resizing of obstructions.
;---------------------------------------

    ; Cut Boundary shapes around the ports with min spacing.
    (Bmetal1 = obsSpace(Bmetal1 m1Ports 0.4)) 
    (Bmetal2 = obsSpace(Bmetal2 m2Ports 0.4)) 
    (Bmetal3 = obsSpace(Bmetal3 m3Ports 0.4)) 
    (Bmetal4 = obsSpace(Bmetal4 m4Ports 0.4))
    (Bmetal5 = obsSpace(Bmetal5 m5Ports 1.8)) 
;    (Bmetal6 = obsSpace(Bmetal6 m6Ports 1.8)) 

    ; Build Obstructions shapes : metal + boundary - ports.
    (m1Obs = geomOr(metal1 Bmetal1)) 
    (m2Obs = geomOr(metal2 Bmetal2)) 
    (m3Obs = geomOr(metal3 Bmetal3)) 
    (m4Obs = geomOr(metal4 Bmetal4)) 
    (m5Obs = geomOr(metal5 Bmetal5))
;    (m6Obs = geomOr(metal6 Bmetal6))
    (m1Obs = geomAndNot(m1Obs m1Ports)) 
    (m2Obs = geomAndNot(m2Obs m2Ports)) 
    (m3Obs = geomAndNot(m3Obs m3Ports))
    (m4Obs = geomAndNot(m4Obs m4Ports)) 
    (m5Obs = geomAndNot(m5Obs m5Ports)) 
;    (m6Obs = geomAndNot(m6Obs m6Ports)) 

    ; Merging obstructions that don't let space for a routing layer.  
    ; => if space between 2 shapes < minSpacing + 1/2 minWidth 
    (m1Obs = obsResize(m1Obs 0.59)) ; 0.4 + 0.5 * 0.4 - 0.01
    (m2Obs = obsResize(m2Obs 0.71)) ; 0.4 + 0.5 * 0.6 + 0.01
    (m3Obs = obsResize(m3Obs 0.71)) ; 0.4 + 0.5 * 0.6 + 0.01
    (m4Obs = obsResize(m4Obs 0.71)) ; 0.4 + 0.5 * 0.6 + 0.01
    (m5Obs = obsResize(m5Obs 2.31)) ; 1.8 + 0.5 * 1.0 + 0.01
;    (m6Obs = obsResize(m6Obs 2.31)) ; 1.8 + 0.5 * 1.0 + 0.01

    ; Remove Ports.
    (m1Obs = geomAndNot(m1Obs m1Ports)) 
    (m2Obs = geomAndNot(m2Obs m2Ports))
    (m3Obs = geomAndNot(m3Obs m3Ports)) 
    (m4Obs = geomAndNot(m4Obs m4Ports)) 
    (m5Obs = geomAndNot(m5Obs m5Ports)) 
;    (m6Obs = geomAndNot(m6Obs m6Ports)) 

    ;  Treatement of obstructions : 
    ;  mxSpace = mxObs cut around ports.
    ;  mxRemove = differences between mxSpace & mxObs
    ;  mxSpace = (mxSpace + ports) => merged.
    ;  mxRemove = mxRemove & mxSpace intersections.
    ;  mxObs = differences between mxObs & mxRemove.
    (m1Space = obsSpace(m1Obs m1Ports 0.4)) 
    (m1Remove = geomAndNot(m1Obs m1Space))
    (m1Space = geomOr(m1Ports m1Space)) 
    (m1Space = obsResize(m1Space 0.59)) 
    (m1Remove = geomAnd(m1Remove m1Space)) 
    (m1Obs = geomAndNot(m1Obs m1Remove)) 
    (m2Space = obsSpace(m2Obs m2Ports 0.4))
    (m2Remove = geomAndNot(m2Obs m2Space)) 
    (m2Space = geomOr(m2Ports m2Space)) 
    (m2Space = obsResize(m2Space 0.71)) 
    (m2Remove = geomAnd(m2Remove m2Space)) 
    (m2Obs = geomAndNot(m2Obs m2Remove))
    (m3Space = obsSpace(m3Obs m3Ports 0.4)) 
    (m3Remove = geomAndNot(m3Obs m3Space)) 
    (m3Space = geomOr(m3Ports m3Space)) 
    (m3Space = obsResize(m3Space 0.71)) 
    (m3Remove = geomAnd(m3Remove m3Space))
    (m3Obs = geomAndNot(m3Obs m3Remove)) 
    (m4Space = obsSpace(m4Obs m4Ports 0.4)) 
    (m4Remove = geomAndNot(m4Obs m4Space)) 
    (m4Space = geomOr(m4Ports m4Space)) 
    (m4Space = obsResize(m4Space 0.71))
    (m4Remove = geomAnd(m4Remove m4Space)) 
    (m4Obs = geomAndNot(m4Obs m4Remove)) 
    (m5Space = obsSpace(m5Obs m5Ports 1.8)) 
    (m5Remove = geomAndNot(m5Obs m5Space)) 
    (m5Space = geomOr(m5Ports m5Space))
    (m5Space = obsResize(m5Space 2.31)) 
    (m5Remove = geomAnd(m5Remove m5Space)) 
    (m5Obs = geomAndNot(m5Obs m5Remove)) 
;    (m6Space = obsSpace(m6Obs m6Ports 1.8)) 
;    (m6Remove = geomAndNot(m6Obs m6Space)) 
;    (m6Space = geomOr(m6Ports m6Space))
;    (m6Space = obsResize(m6Space 2.31)) 
;    (m6Remove = geomAnd(m6Remove m6Space)) 
;    (m6Obs = geomAndNot(m6Obs m6Remove)) 

    ; Obstrcutions for vias on all cell.
    (v1Obs = geomOr(bkgnd)) 
    (v2Obs = geomOr(bkgnd))
    (v3Obs = geomOr(bkgnd)) 
    (v4Obs = geomOr(bkgnd)) 
;    (v5Obs = geomOr(bkgnd)) 


    ; put all obstructions in abstract view.
    saveDerived(m1Obs 
	("metal1" "boundary") abs_view tile
    ) 
    saveDerived(v1Obs 
	("v1" "boundary") abs_view tile
    ) 
    saveDerived(m2Obs 
	("metal2" "boundary") abs_view tile
    ) 
    saveDerived(v2Obs 
	("v2" "boundary") abs_view tile
    ) 
    saveDerived(m3Obs 
	("metal3" "boundary") abs_view tile
    )
    saveDerived(v3Obs 
	("v3" "boundary") abs_view tile
    ) 
    saveDerived(m4Obs 
	("metal4" "boundary") abs_view tile
    ) 
    saveDerived(v4Obs 
	("v4" "boundary") abs_view tile
    ) 
    saveDerived(m5Obs 
	("metal5" "boundary") abs_view tile
    ) 
;    saveDerived(v5Obs 
;	("v5" "boundary") abs_view tile
;    ) 
;    saveDerived(m6Obs 
;	("metal6" "boundary") abs_view tile
;    ) 
    copyGraphics(("metal1" "pintext"))
    copyGraphics(("metal2" "pintext")) 
    copyGraphics(("metal3" "pintext")) 
    copyGraphics(("metal4" "pintext")) 
    copyGraphics(("metal5" "pintext")) 
;    copyGraphics(("metal6" "pintext")) 
    copyGraphics(("text" "drawing"))
    copyGraphics(("pin" "drawing"))
)

