;cv = geGetWindowCellView() 
;geometrie_id=dbCreateRect(cv list("m1" "pin") list(50:50 52:52))
;net_id=dbCreateNet(cv "t")
;dbCreatePin(net_id geometrie_id )
;label=dbCreateLabel(cv "text" 51:51 "t" "upperCenter" "R0" "stick" 0.3)
;leAttachFig(label geometrie_id)	



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

indice = 0
y = 60
defaut_mos = "PMOS"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

procedure(configuration_couche()

	champs_couche = list(
			       list(hiCreateStringField(
							?name    'nom_couche 
						        ?prompt  "Couche" 
						        ?value 	 "" 
						        ?defValue ""   
						       )	
			      (10:30)
			      (200:30)
			      50	


			      )	


		 	      list(hiCreateButton( ?name 'btn_ajouter_couche
			   	                   ?buttonText "Ajouter couche"
				                   ?callback "ajouter_couche()"
				                 )
			      (250:30)
			      (150:30)
			      ;100
			      )
                        )
	
	   indice = indice + 1			
	   hiCreateAppForm( ?name	'Form_config_couche
			 ?fields champs_couche	
			 ?formTitle "# Definition des couches #"
			 ?unmapAfterCB	nil
			 ?initialSize    t
			 ?callback 	"fermer_dialogue()"
		       )
 

	hiDisplayForm('Form_config_couche)

	
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
procedure(ajouter_couche() 
	
   let(()
	   
	   couche_saisie = Form_config_couche->nom_couche->value 

	   ;;;	
	   ;id_label = stringToSymbol(sprintf(nil "label%d" indice))
	   ;id_label = hiCreateLabel( 
	   ;			      ?name id_label 
	   ;			      ?labelText   couche_saisie 
	   ;		          )
	   ;hiAddField(Form_config_couche list(id_label 10:y 200:y-10 150))

	   ;;;
	   id_cycle = stringToSymbol(sprintf(nil "cycle%d" indice)) 
	   id_cycle = hiCreateLayerCyclicField(
						   techGetTechFile(geGetEditCellView()~>lib) 
						   couche_saisie ;"Couche N implant" 
						   "action2()"
						  techGetLeLswLayers(techGetTechFile(geGetEditCellView()~>lib))  
				   		  ()
						  id_cycle
					        )
			
	   hiAddField(Form_config_couche list(id_cycle 10:y 200:45 150))	   

   
	   ;;;

	  id_btn = stringToSymbol(sprintf(nil "btn%d" indice))	
	  id_btn = hiCreateButton( ?name id_btn
			   	    ?buttonText "Supprimer"
				    ?callback "supprimer_couche(id_btn)"
				  )	
	 ; hiAddField(Form_config_couche list(id_btn 300:y 200:40 150))	


	  y = y + 40
	  indice = indice + 1	




	)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
procedure(config_powermos()	  
  
   let(()


	champs =  list(
			list(hiCreateRadioField(
						?name 		'choix_mos
						?choices 	list("PMOS" "NMOS")
						?prompt 	"Type Mos:"
						?value 		defaut_mos ;"PMOS"
						?defValue 	defaut_mos ;"PMOS"
						?callback 	list("choix_type_mos()")
		                               )
			     (0:0)
			     (200:30)
			     150	
			)

			list(hiCreateCyclicField(
						 ?name 'cyclic_facteur_forme 
						 ?prompt "Facteur de forme: " 
			     			 ?choices list("Rectangulaire" "Carre" "U") 
			 		         ?value "Rectangulaire"
						 ?defValue "Rectangulaire" 
					         ?callback  "ajouter_champs()"
						)
			     (10:30)
			     (200:30)
			     150 
			)


			list(hiCreateButton( 
					    ?name 'btn_configuration_couche
				            ?buttonText "Couche"
  				            ?callback "configuration_couche()"
				           )
			     (300:30)
			     (100:25)
			     150 
		        )

			list(hiCreateButton( 
					    ?name 'btn_configuration_regle
				            ?buttonText "Regle"
  				            ?callback "configuration_regle()"
				           )
			     (450:30)
			     (100:25)
			     150 
		        )


		)

	hiCreateAppForm( ?name	'Form_config_powermos
			 ?fields       champs	
			 ?formTitle "# Definition du Power MOS #"
			 ?unmapAfterCB	nil
			 ?initialSize    t
			 ?callback 	"generation()"
		       )

	hiDisplayForm('Form_config_powermos)
	
   );let

);procedure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
procedure(choix_type_mos() 
	
	let(()

		if(type_mos~>value == "PMOS" then
		   println("Choix : PMOS")
		   defaut_mos = "PMOS"
			
		);
		if(type_mos~>value == "NMOS" then
		   println("Choix : NMOS")
		   defaut_mos = "NMOS"	
			
		);

			
	);let
);
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

procedure(configuration_regle() 


		
		;Contwidth = 0.30
		;contSpa = 0.30	
		;met1ContEn = 0.09
		;polymet1spa = 0.13
		;aamet1Enx = 0.05 
		;aamet1Eny = 0.06
		;polyaaExt = 0.3




	champs_regles =  list(
			       list(hiCreateFloatField(
							?name 'contwidth
				                        ?value 0.0
				                        ?prompt "Largeur contact"
				                        ?defValue 0.0
 			                                ?range list(0.0 1.0)
				                        ?editable t
		                                      )
                                   
			            (0:30)
			            (200:30)
			            150	
				)

				list(hiCreateFloatField(
							?name 'contspa
				                        ?value 0.0
				                        ?prompt "Distance contact"
				                        ?defValue 0.0
 			                                ?range list(0.0 1.0)
				                        ?editable t
		                                      )
                                   
			            (0:60)
			            (200:30)
			            150	
				)


				list(hiCreateFloatField(
							?name 'met1conten
				                        ?value 0.0
				                        ?prompt "Met1_cont_En"
				                        ?defValue 0.0
 			                                ?range list(0.0 1.0)
				                        ?editable t
		                                      )
                                   
			            (0:90)
			            (200:30)
			            150	
				)
			         
				list(hiCreateFloatField(
							?name 'polymet1spa
				                        ?value 0.0
				                        ?prompt "Poly_met1_spa"
				                        ?defValue 0.0
 			                                ?range list(0.0 1.0)
				                        ?editable t
		                                      )
                                   
			            (0:120)
			            (200:30)
			            150	
				)

				list(hiCreateFloatField(
							?name 'aamet1enx
				                        ?value 0.0
				                        ?prompt "active_met1_en_x"
				                        ?defValue 0.0
 			                                ?range list(0.0 1.0)
				                        ?editable t
		                                      )
                                   
			            (0:150)
			            (200:30)
			            150	
				)

				list(hiCreateFloatField(
							?name 'aamet1eny
				                        ?value 0.0
				                        ?prompt "active_met1_en_y"
				                        ?defValue 0.0
 			                                ?range list(0.0 1.0)
				                        ?editable t
		                                      )
                                   
			            (0:180)
			            (200:30)
			            150	
				)

				list(hiCreateFloatField(
							?name 'polyaaext
				                        ?value 0.0
				                        ?prompt "Poly_active_ext"
				                        ?defValue 0.0
 			                                ?range list(0.0 1.0)
				                        ?editable t
		                                      )
                                   
			            (0:210)
			            (200:30)
			            150	
				)	

		          )


	
		


	hiCreateAppForm( ?name	'Form_config_regles
			 ?fields       champs_regles	
			 ?formTitle "# Regles #"
			 ?unmapAfterCB	nil
			 ?initialSize    t
			 ?callback 	"generation()"
		       )

	hiDisplayForm('Form_config_regles)


)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

procedure(ajouter_champs() 
	
   let(()

	;liste_champs = Form_config_powermos->fieldList

	; nettoyage
	;for(i 0 length(liste_champs)-1
            	
	;    if(nth(i liste_champs) == "un" then
	;       hiDeleteFields(Form_config_powermos un)
	;    )	
	;    if(nth(i liste_champs) == "deux" then
	;       delete
	;    )	
	;    if(nth(i liste_champs) == "trois" then
	;       delete
	;    )	
	;);
		
	
	if(Form_config_powermos->cyclic_facteur_forme->value == "Rectangulaire" then
	  
	   champ_pcell_nombre_grille = hiCreateIntField(?name 'pcell_nombre_grille
		 		                        ?value 1
				                        ?prompt "Nombre grille"
				                        ?defValue 1
 			                                ?range list(1 1000)
				                        ?editable t
		                                      )
	   hiAddField(Form_config_powermos list(champ_pcell_nombre_grille 10:120 200:30 150))

	   champ_pcell_hauteur_grille = hiCreateFloatField(?name 'pcell_hauteur_grille
				                            ?value 0.0
				                            ?prompt "Hauteur grille"
				                            ?defValue 0.0
 			                                    ?range list(0.0 1000.0)
				                            ?editable t
		                                           )
	   hiAddField(Form_config_powermos list(champ_pcell_hauteur_grille 10:150 200:30 150))

           champ_pcell_largeur_grille = hiCreateFloatField(?name 'pcell_largeur_grille
				                           ?value 0.0
				                           ?prompt "Largeur grille"
				                           ?defValue 0.0
 			                                   ?range list(0.0 1000.0)
				                           ?editable t
		                                          )
	   hiAddField(Form_config_powermos list(champ_pcell_largeur_grille 10:180 200:30 150))		

	   champ_powermos_ligne = hiCreateIntField(?name 'powermos_ligne
				                   ?value 1
				                   ?prompt "Nombre de ligne"
				                   ?defValue 1
 			                           ?range list(1 1000)
				                   ?editable t
		                                  )
	   hiAddField(Form_config_powermos list(champ_powermos_ligne 10:210 200:30 150))
	   
	   champ_powermos_colonne = hiCreateIntField(?name 'powermos_colonne
				                     ?value 1
				                     ?prompt "Nombre de colonne"
				                     ?defValue 1
 			                             ?range list(1 1000)
				                     ?editable t
		                                    )

	   hiAddField(Form_config_powermos list(champ_powermos_colonne 10:240 200:30 150))

	   champ_pcell_contact_ring = hiCreateIntField(?name 'pcell_contact_ring
				                       ?value 1
				                       ?prompt "Nombre de contact pour le ring"
				                       ?defValue 1
 			                               ?range list(1 20)
				                       ?editable t
		                                     )
	   hiAddField(Form_config_powermos list(champ_pcell_contact_ring 10:270 200:30 150))

	   champ_nom_librairie = hiCreateStringField(?name 'nom_librairie 
						     ?prompt 	"Nom librairie" 
						     ?value 	"" 
						     ?defValue 	""   
						    )						

	   hiAddField(Form_config_powermos list(champ_nom_librairie 10:300 200:30 150))	

           champ_largeur_slot = hiCreateFloatField(?name 'largeur_slot
				                   ?value 0.0
				                   ?prompt "Largeur slot"
				                   ?defValue 0.0
 			                           ?range list(0.0 1000.0)
				                   ?editable t
		                                   )
           hiAddField(Form_config_powermos list(champ_largeur_slot 10:330 200:30 150))	

           champ_hauteur_slot = hiCreateFloatField(?name 'hauteur_slot
				                   ?value 0.0
				                   ?prompt "Hauteur slot"
				                   ?defValue 0.0
 			                           ?range list(0.0 1000.0)
				                   ?editable t
		                                   )
           hiAddField(Form_config_powermos list(champ_hauteur_slot 10:370 200:30 150))	
		
           champ_slot_distance_x = hiCreateFloatField(?name 'slot_distance_x
				                   ?value 0.0
				                   ?prompt "Distance x"
				                   ?defValue 0.0
 			                           ?range list(0.0 1000.0)
				                   ?editable t
		                                   )
           hiAddField(Form_config_powermos list(champ_slot_distance_x 10:400 200:30 150))	
		
	   champ_slot_distance_y = hiCreateFloatField(?name 'slot_distance_y
				                   ?value 0.0
				                   ?prompt "Distance y"
				                   ?defValue 0.0
 			                           ?range list(0.0 1000.0)
				                   ?editable t
		                                   )
           hiAddField(Form_config_powermos list(champ_slot_distance_y 10:430 200:30 150))	
			


	   champ_btn_generer_pcell = hiCreateButton( ?name 'btn_generer_pcell
				                        ?buttonText "Generer Pcell"
  				                        ?callback "generateur_pcell()"
				                      )

           hiAddField(Form_config_powermos list(champ_btn_generer_pcell 10:500 150:30 150))	

	   champ_btn_generer_powermos = hiCreateButton( ?name 'btn_generer_powermos
				                        ?buttonText "Generer PowerMos"
  				                        ?callback "forme_rectangulaire()"
						        ?enabled nil
				                      )

           hiAddField(Form_config_powermos list(champ_btn_generer_powermos 250:500 150:30 150))	
	)
	



   );let

);
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
procedure(generer_esd() 

	nom_vue = "cellpdl"
    

    pcDefinePCell(
    
    
    cellId = list( ddGetObj( "be08aProj" )  "cellpdl"   "layout" )
   
   

                    (   (fingers   1)   ; number of gates in series
                    (m         1)   ; number of gates in parallel
                    (w_microns 1.0)   ; width in microns
                    (l_microns 1.0)   ; length in microns
                )

	  esd()

     dbReplaceProp( cv "viewSubType" "string" "maskLayoutParamCell")
     dbReplaceProp( cv "function" "string" "transistor" )	
	
     
     printf("[Info]: Pcell %s generated ): \n" nom_vue )
     

     );pcDefinePCell

);procedure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

procedure(esd() 

   

pcDefinePCell(	

	 cellId = list( ddGetObj( "be08aProj" )  "cellpdl"   "layout" )
   
   

                    (   (fingers   1)   ; number of gates in series
                    (m         40)   ; number of gates in parallel
                    (w_microns 1.0)   ; width in microns
                    (l_microns 1.0)   ; length in microns
                )

	 
	 ;cv = geGetWindowCellView() 

	 cv = pcCellView

         rod_active=rodCreateRect(
				?cvId		cv
		 		?layer		"aa"
				?bBox		list(0:0 9.88:40)
				) 


	Layer1 = rodCreateRect(
				?cvId		cv
		 		?layer		"nimp"
				?width		9.88+2*0.26
				?length		m+2*0.44 ;40

				)

	Layer2 = rodCreateRect(
				?cvId		cv
		 		?layer		"nthk"
				?width		9.88+2*0.26
				?length		40+2*0.44
				)
	Layer3 = rodCreateRect(
				?cvId		cv
		 		?layer		"to5"
				?width		9.88+2*0.26
				?length		40+2*0.44
				)

		rodAlign(
			?refObj		 rod_active
			?refHandle	"lowerLeft"
			?alignObj	Layer1
			?alignHandle	"lowerLeft"
			?xSep		-0.26
			?ySep		-0.44
			)



		rodAlign(
			?refObj		 rod_active
			?refHandle	"lowerLeft"
			?alignObj	Layer2
			?alignHandle	"lowerLeft"
			?xSep		-0.26
			?ySep		-0.44
			)

		rodAlign(
			?refObj		 rod_active
			?refHandle	"lowerLeft"
			?alignObj	Layer3
			?alignHandle	"lowerLeft"
			?xSep		-0.26
			?ySep		-0.44
			)

;contWidth = 0.3
;		met1ContEn = 0.09
;		aamet1Enx = 0.05
;		aamet1Eny = 0.06
;		contSpa = 0.30
;		polymet1Spa = 0.13
;		polyaaext = 0.30

		for( i 0 1
			sourceOrDrain[i] = rodCreatePath(
				         		  ?layer		"m1"
			  				  ?cvId			cv
							  ?width		0.48
							  ?pts			list(0:0 0:40-2*0.06)
							  ?justification	"center"
							  ?subRect	list(
						      				list(
			  						              ?layer		"co"
									              ?length		0.3
									              ?width		0.3
									              ?space		0.3
									              ?beginOffset	-0.13
									              ?endOffset        -0.13
								                )
								        )

				                         )

		
		


		);end for


		rodAlign(
			?refObj		rod_active
			?refHandle	"lowerLeft"      ;upperLeft
			?alignObj	sourceOrDrain[0]
			?alignHandle	"lowerLeft"
			?xSep		0.05
			?ySep		0.06
			)

		rodAlign(
			?refObj		rod_active
			?refHandle	"lowerRight"      ;upperLeft
			?alignObj	sourceOrDrain[1]
			?alignHandle	"lowerRight"
			?xSep		-0.05
			?ySep		0.06
			)


		milieu = 9.88/2.0

		h = 40.0-2*0.9


		rod_milieu = rodCreatePath(
				         		  ?layer		"m1"
			  				  ?cvId			cv
							  ?width		0.48
							  ?pts			list(0:0 0:40-2*0.9)
							  ?justification	"center"
							  ?subRect	list(
						      				list(
			  						              ?layer		"co"
									              ?length		0.3
									              ?width		0.3
									              ?space		0.3
									              ?beginOffset	-0.13
									              ?endOffset        -0.13
								                )
								        )

				                         )

		rodAlign(
			?refObj		rod_active
			?refHandle	"lowerLeft"      
			?alignObj	rod_milieu
			?alignHandle	"lowerLeft"
			?xSep		milieu - 0.24
			?ySep		0.9
			)

		;;; grille
		grille_gauche = rodCreateRect(
				?cvId		cv
		 		?layer		"p1"
				?width		0.5
				?length		40+2*0.3
				)

		rodAlign(
			?refObj		rod_active
			?refHandle	"lowerLeft"      
			?alignObj	grille_gauche
			?alignHandle	"lowerLeft"
			?xSep		1.49
			?ySep		-0.30
			)


		grille_droite = rodCreateRect(
				?cvId		cv
		 		?layer		"p1"
				?width		0.5
				?length		40+2*0.3
				)

		rodAlign(
			?refObj		rod_active
			?refHandle	"lowerRight"      
			?alignObj	grille_droite
			?alignHandle	"lowerRight"
			?xSep		-1.49
			?ySep		-0.30
			)


		x1 = 0.05
		y1 = 0.06
		x2 = x1 + 0.48
		y2 = 40-2*0.06 + 0.06
		x_milieu = 0.05 + 0.48/2
		leCreatePin(cv list("m1" "pin") "rectangle" list(x1:y1 x2:y2) "s" "input" list("left" "right"))
		dbCreateLabel(cv "text" x_milieu:(40-2*0.06)/2 "s" "centerCenter" "R0" "stick" 0.3)

		x1 = 9.88 - 0.05 - 0.48
		y1 = 0.06
		x2 = x1 + 0.48
		y2 = 40-2*0.06 + 0.06
		x_milieu = 9.88 - 0.05 - 0.48/2
		leCreatePin(cv list("m1" "pin") "rectangle" list(x1:y1 x2:y2) "s" "input" list("left" "right"))
		dbCreateLabel(cv "text" x_milieu:(40-2*0.06)/2 "s" "centerCenter" "R0" "stick" 0.3)


		x1 = (9.88 /2) - (0.48/2)
		y1 = 0.9
		x2 = x1 + 0.48
		y2 = 40-2*0.9 + 0.9 
		x_milieu = x1 + (0.48/2)
		leCreatePin(cv list("m1" "pin") "rectangle" list(x1:y1 x2:y2) "d" "input" list("left" "right"))
		dbCreateLabel(cv "text" x_milieu:y2/2 "d" "centerCenter" "R0" "stick" 0.3)



		x1 = 1.49 ; 0.05 + 0.48 + 0.96
		y1 = -0.30
		x2 = x1 + 0.50
		y2 = 40 + 0.3
		x_milieu = x1 + (0.5/2)
		leCreatePin(cv list("p1" "pin") "rectangle" list(x1:y1 x2:y2) "g" "input" list("left" "right"))
		dbCreateLabel(cv "text" x_milieu:40/2 "g" "centerCenter" "R0" "stick" 0.3)
		dbCreateLabel(cv "lvstxt" x_milieu:40/2+3 "NMOS5V" "centerCenter" "R90" "stick" 0.3)



		x1 = 9.88 - 0.05 - 0.48 - 0.96 - 0.5
		y1 = -0.30
		x2 = x1 + 0.50
		y2 = 40 + 0.3
		x_milieu = x1 + (0.5/2)
		leCreatePin(cv list("p1" "pin") "rectangle" list(x1:y1 x2:y2) "g" "input" list("left" "right"))
		dbCreateLabel(cv "text" x_milieu:40/2 "g" "centerCenter" "R0" "stick" 0.3)
		dbCreateLabel(cv "lvstxt" x_milieu:40/2+3 "NMOS5V" "centerCenter" "R90" "stick" 0.3)


		x1 = 9.88 - 0.05 - 0.48 - 0.96 - 0.5
		y1 = -0.30
		
		dbCreateLabel(cv "devtxt" 9.88/2: 40/2 "[@instanceName]" "centerCenter" "R0" "stick" 1)



      );pcellview


  

)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
procedure(custom() 

   let( (largeur hauteur)

;Form_config_regles~>contwidth~>value 
;Form_config_regles~>contspa~>value
;Form_config_regles~>met1conten~>value
;Form_config_regles~>polymet1spa~>value
;Form_config_regles~>aamet1enx~>value 
;Form_config_regles~>aamet1eny~>value
;Form_config_regles~>polyaaext~>value



		declare(sourceOrDrain[301])
		declare(gate[300])
		declare(geometrie_id[100])		

		finger = 3
		width = 20
		length = 3

;		contWidth = 0.3
;		met1ContEn = 0.09
;		aamet1Enx = 0.05
;		aamet1Eny = 0.06
;		contSpa = 0.30
;		polymet1Spa = 0.13
;		polyaaext = 0.30

		met1SDwidth = width - (2*Form_config_regles~>aamet1eny~>value)
		polygrillewidth = width + (2*Form_config_regles~>polyaaext~>value)
		met1SDSpa = length + (2*Form_config_regles~>polymet1spa~>value) 
		met1SDlength = (2*Form_config_regles~>met1conten~>value) + Form_config_regles~>contwidth~>value 

		layer_met1 = "m1"
		layer_cont = "co"
		layer_poly = "p1"
		layer_active = "aa"
		
		layer_tech1 = "pthk"
		layer_tech1 = "pimp"
		layer_tech1 = "to5"
		layer_tech1 = "nw"


		cv = geGetWindowCellView() 

		;====================================================================================
		; source et drain + contact + via + via1 + via2 + via3 + via4 
		;====================================================================================
		indice = 0

		for( i 0 finger
			sourceOrDrain[i] = rodCreatePath(
				         		  ?layer		layer_met1
			  				  ?cvId			cv
							  ?width		met1SDlength
							  ?pts			list(0:0 0:met1SDwidth)
							  ?justification	"center"
							  ?subRect	list(
						      				list(
			  						              ?layer		layer_cont
									              ?length		Form_config_regles~>contwidth~>value
									              ?width		Form_config_regles~>contwidth~>value
									              ?space		Form_config_regles~>contspa~>value
									              ?beginOffset	-Form_config_regles~>polymet1spa~>value
									              ?endOffset        -Form_config_regles~>polymet1spa~>value
								                )
								        )

				                         )

		
		delta = i*(length + (2*Form_config_regles~>polymet1spa~>value)) + (i*met1SDlength)
		x1= delta - (met1SDlength / 2)
		y1 = 0
		x2 = delta + (met1SDlength / 2)
		y2 = met1SDwidth			

		if( oddp(i) == nil then  ; pair
		  
		    nom = "s"   	

		)

		if( oddp(i) == t then  ; impair

		 nom = "d"   
		)

		leCreatePin(cv list("m1" "pin") "rectangle" list(x1:y1 x2:y2) nom "input" list("left" "right"))
		dbCreateLabel(cv "text" delta:(met1SDwidth/2) nom "centerCenter" "R0" "stick" 0.3)


		);end for

		;====================================================================================
		; grille
		;====================================================================================f
		
		for( i 0 (finger-1)
			gate[i] = rodCreateRect(
				?cvId		cv
				?layer		layer_poly
				?width		length
				?length		polygrillewidth
				)
			rodAlign(
				?refObj		sourceOrDrain[i]
				?refHandle	"upperRight"
				?alignObj	gate[i]
				?alignHandle	"upperLeft"
				?xSep		Form_config_regles~>polymet1spa~>value
				?ySep		Form_config_regles~>polyaaext~>value + Form_config_regles~>aamet1eny~>value   
				)
			
			rodAlign(
				?refObj		gate[i]
				?refHandle	"upperRight"
				?alignObj	sourceOrDrain[i+1]
				?alignHandle	"upperLeft"
				?xSep		Form_config_regles~>polymet1spa~>value
				?ySep		-Form_config_regles~>polyaaext~>value - Form_config_regles~>aamet1eny~>value  
				)	

		Form_config_regles~>polymet1Spa~>value
delta = (met1SDlength / 2) + Form_config_regles~>polymet1spa~>value  + i*(length + (2*Form_config_regles~>polymet1spa~>value)) + (i*met1SDlength)

		x1 = delta
		y1 = -Form_config_regles~>polyaaext~>value - Form_config_regles~>aamet1eny~>value
		x2 = delta + length
		y2 = width + Form_config_regles~>polyaaext~>value - Form_config_regles~>aamet1eny~>value

		leCreatePin(cv list("p1" "pin") "rectangle" list(x1:y1 x2:y2) "g" "input" list("left" "right"))
		dbCreateLabel(cv "text" x1 +(length/2):(y2/2) "G" "centerCenter" "R0" "stick" 0.3)
		
		dbCreateLabel(cv "lvstxt" x1 + (length / 2):(y2 / 2) "PMOS5V" "centerCenter" "R90" "stick" 0.3)
			
		;);end for

		;====================================================================================
		; construction des couches  
		;====================================================================================
		
largeur_shape = (length + (2*Form_config_regles~>polymet1spa~>value))*finger + (finger+1)*((2*Form_config_regles~>met1conten~>value) + Form_config_regles~>contspa~>value) + (2*Form_config_regles~>aamet1enx~>value)
	        hauteur_shape = width 
		
		Layer1 = rodCreateRect(
				?cvId		cv
		 		?layer		layer_active
				?width		largeur_shape
				?length		hauteur_shape
				)
		rodAlign(
			?refObj		sourceOrDrain[0]
			?refHandle	"lowerLeft"
			?alignObj	Layer1
			?alignHandle	"lowerLeft"
			?xSep		-Form_config_regles~>aamet1enx~>value
			?ySep		-Form_config_regles~>aamet1eny~>value
			)

;;;

	pthkaaEnx = 0.26
	pthkaaEny = 0.32

		largeur_shape = largeur_shape + 2*pthkaaEnx
	        hauteur_shape = hauteur_shape + 2*pthkaaEny
		
		Layer2 = rodCreateRect(
				?cvId		cv
		 		?layer		"pthk"
				?width		largeur_shape
				?length		hauteur_shape
				)
		rodAlign(
			?refObj		Layer1
			?refHandle	"lowerLeft"
			?alignObj	Layer2
			?alignHandle	"lowerLeft"
			?xSep		-pthkaaEnx
			?ySep		-pthkaaEny
			)
;;;

		pimppthkEnx = 0.0
		pimppthkEny = 0.12

		largeur_shape = largeur_shape + 2*pimppthkEnx
	        hauteur_shape = hauteur_shape + 2*pimppthkEny
		
		
		Layer3 = rodCreateRect(
				?cvId		cv
		 		?layer		"pimp"
				?width		largeur_shape
				?length		hauteur_shape
				)
		rodAlign(
			?refObj		Layer2
			?refHandle	"lowerLeft"
			?alignObj	Layer3
			?alignHandle	"lowerLeft"
			?xSep		-pimppthkEnx
			?ySep		-pimppthkEny
			)


;;;

		to5pimppEnx = 0.0
		to5pimppEny = 0.01

		largeur_shape = largeur_shape + 2*to5pimppEnx
	        hauteur_shape = hauteur_shape + 2*to5pimppEny
		
		
		Layer4 = rodCreateRect(
				?cvId		cv
		 		?layer		"to5"
				?width		largeur_shape
				?length		hauteur_shape
				)
		rodAlign(
			?refObj		Layer3
			?refHandle	"lowerLeft"
			?alignObj	Layer4
			?alignHandle	"lowerLeft"
			?xSep		-to5pimppEnx
			?ySep		-to5pimppEny
			)

;;;

		nwto5Enx = 0.34
		nwto5Eny = 0.15

		largeur_shape = largeur_shape + 2*nwto5Enx
	        hauteur_shape = hauteur_shape + 2*nwto5Eny
		
		
		Layer5 = rodCreateRect(
				?cvId		cv
		 		?layer		"nw"
				?width		largeur_shape
				?length		hauteur_shape
				)
		rodAlign(
			?refObj		Layer4
			?refHandle	"lowerLeft"
			?alignObj	Layer5
			?alignHandle	"lowerLeft"
			?xSep		-nwto5Enx
			?ySep		-nwto5Eny
			)
;;;

		pinnwx = 0.0
		pinnwy = 0.0

		Layer6 = rodCreateRect(
				?cvId		cv
		 		?layer		list("nw" "pin")
				?width		largeur_shape
				?length		hauteur_shape
				)
		rodAlign(
			?refObj		Layer5
			?refHandle	"lowerLeft"
			?alignObj	Layer6
			?alignHandle	"lowerLeft"
			?xSep		0
			?ySep		0
			)




   );let






pcDefinePCell(
        list(ddGetObj("roland_pcells") "mpbl" "layout")
                (
                        (width float 1.4)
                        (length float 0.6)
                )

                pact =  rodCreateRect(
                         ?name "pact"
                         ?cvId pcCellView
                         ?layer "pact"
                         ?bBox list(0:0 length+4:width)
                );end rod

                pgate = rodCreateRect(
                         ?name "pgate"
                         ?cvId pcCellView
                         ?layer "pgate"
                         ?bBox list(2:-.6 2+length:width+.6)
                );end rod

                rodAssignHandleToParameter(
                        ?parameter               "width"
                        ?rodObj                  pact
                        ?handleName              list("upperCenter")
                        ?displayName             "width"
                        ?stretchDir              "y"
                        ?stretchType             "relative"
                        ?moveOrigin              t
                 ) ; end rodAssignHandleToParameter

                rodAssignHandleToParameter(
                        ?parameter               "length"
                        ?rodObj                  pgate
                        ?handleName              list("lowerRight")
                        ?displayName             "length"
                        ?stretchDir              "x"
                        ?stretchType             "relative"
                        ?moveOrigin              t
                 ) ; end rodAssignHandleToParameter

                t
) 

) 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;config_powermos()
;configuration_couche()
