rotate_silkassy文件改進

 之前使用的對齊絲印層ref的il文件,rotate_silkassy  原始的文件是根據 place 層的 shape 來計算中心位置的。

但是我後來發現 如果 place層中如果有 線段,這個il文件就會把中心定位到 最後一個線段的 中心,這樣就偏離的。

我改進後,計算各個 place層對象的bbox面積。 然後定位到 面積最大的那個對象上面,以面積最大的bbox的中心來定位。

add by  louix

 

printf("############\n");
            max_aera=0.0
            foreach(childid, txtObj ->parent ->children

                when(childid ->layer == "PACKAGE GEOMETRY/PLACE_BOUND_TOP" || childid ->layer == "PACKAGE GEOMETRY/PLACE_BOUND_BOTTOM"
                    printf("childid ->bBox:%L\n",childid ->bBox)
                    delta_x =( xCoord(cadr(childid ->bBox)) - xCoord(car(childid ->bBox)))
                    delta_y =( yCoord(cadr(childid ->bBox)) - yCoord(car(childid ->bBox)))
                    current_aera=delta_x*delta_y

                    printf("dx:%f;dy=%f;current_aera=%f;max_aera=%f\n",delta_x,delta_y,current_aera,max_aera)
                    if((current_aera > max_aera) then
                         max_aera = current_aera 
                         printf("max_aera=%f\n" , max_aera)
                         sym_x =(xCoord(car(childid ->bBox)) + xCoord(cadr(childid ->bBox))) / 2.0
                         sym_y =(yCoord(car(childid ->bBox)) + yCoord(cadr(childid ->bBox))) / 2.0
                    )    


                      );when childid
            );end foreach childid

 

 

;###########################################################################
;#                                                                         #
;#   Rotate Reference Designator Text on Silkscreen and Assembly Layers    #
;#                                                                         #
;#  This routine rotates Silkscreen and Assembly Reference Designators     #
;#  such that they are all "rightward reading".  This means that all RDs   #
;#  will read left to right if they are horizontal, or bottom to top if    #
;#  they are vertical.                                                     #
;#                                                                         #
;#  Additionally, any Assy RD will automatically be moved to the component #
;#  origin.                                                                #
;#                                                                         #
;#                                                                         #
;#  Usage:  rotate_silkassy (from within Allegro)                          #
;###########################################################################

/*
	History:
 	2.0	26-Jan-11	DE	Commented out SetupDir() and inserted FormDir = "./"
 	2.1	07-Jun-12	DE	Added feature to skip text with fixed or locked parents.
 	2.2	21-May-15	DE	Re-wrote for 16.6 and stricter Skill coding style. Added prefix fields.
*/

;load(strcat(eval('mySkillPath), "\\RotateSilkAssyRD.il"))
;AFn_lint(strcat(eval('mySkillPath), "\\RotateSilkAssyRD.il"))

;##########################
;#  Register Program Name #
;##########################

axlCmdRegister("rotate_silkassy" 'RotateSilkAssyRD)

;#############################
;# MAIN Program Starts Here. #
;#############################

defun( RotateSilkAssyRD ()
 let((fStr, embFID, form, formFile)
	if( axlOKToProceed() then
		; ==== Create and Display the User Interface ====
		unless(boundp('RotateSilkAssyRD_mediumPrefixes), defvar(RotateSilkAssyRD_mediumPrefixes, "RN, RP, FB, KP"))
		unless(boundp('RotateSilkAssyRD_smallPrefixes), defvar(RotateSilkAssyRD_smallPrefixes, "C, R, D, TP"))
		fStr = createRotateRDFormStr()
		if(axlVersion('version) >= 16.6 then
			embFID = gensym()
			form = axlFormCreate(embFID, list(sprintf(nil, "embeddedForm_%s", embFID), list(fStr)), nil, 'rotateRDForm_Action, t)
		 else
			formFile = "rotateRDForm.form"
			form = axlDMOpenFile("FORM", formFile, "w")
			fprintf(form, createRotateRDFormStr())
  		axlDMClose(form)
			form = axlFormCreate((gensym), formFile, nil, 'rotateRDForm_Action, t)
		)
		axlFormSetField(form, "LRBT", t); Default is Left to Right, Bottom to Top
		axlFormSetField(form "CenterAssy", t)
		axlFormSetField(form "TextBlockLarge", 6)
		axlFormSetField(form "TextBlockMedium", 3)
		axlFormSetField(form "TextBlockSmall", 1)
		axlFormSetField(form, "mediumPrefixes", RotateSilkAssyRD_mediumPrefixes)
		axlFormSetField(form, "smallPrefixes", RotateSilkAssyRD_smallPrefixes)
		axlFormDisplay(form)
		when(formFile, deleteFile(formFile))
	 else
		printf("E- Please terminate your interactive command .\n")
	);endif OKToProceed
)); end defun - MAIN Program

;############################################################################
;# DoRotateSilkAssy - When OK is hit, perform Reference Designator Rotation #
;#                   Do each layer separately to improve performance.       #
;############################################################################

defun( DoRotateSilkAssy (form)
 let((okFixed, allTxtObjs, layers, layerTxtObjs)
	okFixed = axlFormGetField(form, "okfixed")
	axlClearSelSet()
	axlSetFindFilter(?enabled '("noall", "text", "invisible"), ?onButtons '("text"))
	allTxtObjs = axlGetSelSet(axlAddSelectAll())
	axlClearSelSet()
	axlMsgPut("Silk/Assy RD rotation started.")
	axlVisibleLayer("BOARD GEOMETRY/OUTLINE", t)
	when(axlFormGetField(form, "AssyBot")
		axlVisibleLayer("PACKAGE GEOMETRY/ASSEMBLY_BOTTOM", t)
		axlVisibleLayer("REF DES/ASSEMBLY_BOTTOM", t)
		layers = cons("REF DES/ASSEMBLY_BOTTOM", layers)
	)
	when(axlFormGetField(form, "AssyTop")
		axlVisibleLayer("PACKAGE GEOMETRY/ASSEMBLY_TOP", t)
		axlVisibleLayer("REF DES/ASSEMBLY_TOP", t)
		layers = cons("REF DES/ASSEMBLY_TOP", layers)
	)
	when(axlFormGetField(form, "SilkBot")
		axlVisibleLayer("PACKAGE GEOMETRY/SILKSCREEN_BOTTOM", t)
		axlVisibleLayer("REF DES/SILKSCREEN_BOTTOM", t)
		layers = cons("REF DES/SILKSCREEN_BOTTOM", layers)
	)
	when(axlFormGetField(form, "SilkTop")
		axlVisibleLayer("PACKAGE GEOMETRY/SILKSCREEN_TOP", t)
		axlVisibleLayer("REF DES/SILKSCREEN_TOP", t)
		layers = cons("REF DES/SILKSCREEN_TOP", layers)
	)
	foreach(layer, layers
		layerTxtObjs = setof(txtObj, allTxtObjs, txtObj ->layer == layer)
		unless(okFixed, layerTxtObjs = setof(txtObj, layerTxtObjs, !axlDBIsFixed(txtObj ->parent) && !txtObj ->parent ->prop ->LOCKED))
		unless(zerop(length(layerTxtObjs)), RotateSilkAssy(form, layerTxtObjs))
		axlMsgPut(strcat(layer, ": Rotation completed."))
	); foreach layer
)); end defun - DoRotateSilkAssy

;######################################################################
;# RotateSilkAssy - Check layer type, Get RD Coordinates and rotation.#
;#                  Rotate RD in place if wrong orientation, change   #
;#                  text justification to "center".                   #
;######################################################################

defun( RotateSilkAssy (form, txtObjs)
 let((mediumPrefixes, smallPrefixes, changeit, text, xy, txt_tblk, txt_rot, rdPrefix, sym_x, sym_y, halfTextHeight, textOrientation)
	mediumPrefixes = parseString(axlFormGetField(form, "mediumPrefixes"), ", ")
	smallPrefixes = parseString(axlFormGetField(form, "smallPrefixes"), ", ")
	foreach(txtObj, txtObjs
		; ==== retrieve current information on text id              ====
		changeit = nil
		text = txtObj ->text
		xy = txtObj ->xy
		txt_tblk = readstring(txtObj ->textBlock)
		; ==== Change Text to "Center" Justification for ease of use ====
		unless(txtObj ->justify == "CENTER", changeit = t)
		; ==== Check current rotation against preferred orientation and change if necessary ====
		txt_rot = round(txtObj ->rotation)
		cond(
			(axlFormGetField(form, "LRBT") && txt_rot == 180, txt_rot =   0, changeit = t)
			(axlFormGetField(form, "LRBT") && txt_rot == 270, txt_rot =  90, changeit = t)
			(axlFormGetField(form, "LRTB") && txt_rot == 180, txt_rot =   0, changeit = t)
			(axlFormGetField(form, "LRTB") && txt_rot ==  90, txt_rot = 270, changeit = t)
			(axlFormGetField(form, "RLBT") && txt_rot == 180, txt_rot =   0, changeit = t)
			(axlFormGetField(form, "RLBT") && txt_rot == 270, txt_rot =  90, changeit = t)
			(axlFormGetField(form, "RLTB") && txt_rot == 180, txt_rot =   0, changeit = t)
			(axlFormGetField(form, "RLTB") && txt_rot ==  90, txt_rot = 270, changeit = t)
		)
		; ==== ON Assembly Layers, if requested by user in form move Assy Text to Calculated Symbol origin    ====
		; ====    Change Text Block Sizes for easier reading.   ====
		when(axlFormGetField(form, "ChangeTextSize")
			changeit = t
			rdPrefix = car(parseString(text, "0123456789"))
			txt_tblk = cond(
				;(listnindex('("RN", "RP", "FB", "KP"), rdPrefix), axlFormGetField(form, "TextBlockMedium"))
				(listnindex(mediumPrefixes, rdPrefix), axlFormGetField(form, "TextBlockMedium"))
				;(listnindex('("C", "R", "D", "TP"), rdPrefix), axlFormGetField(form, "TextBlockSmall"))
				(listnindex(smallPrefixes, rdPrefix), axlFormGetField(form, "TextBlockSmall"))
				(t, axlFormGetField(form, "TextBlockLarge"))
			)
		)
		when(axlFormGetField(form "CenterAssy")
			;rotate_silkassy
			printf("############\n");add  by  louis
			max_aera=0.0
			foreach(childid, txtObj ->parent ->children

				when(childid ->layer == "PACKAGE GEOMETRY/PLACE_BOUND_TOP" || childid ->layer == "PACKAGE GEOMETRY/PLACE_BOUND_BOTTOM"
					printf("childid ->bBox:%L\n",childid ->bBox)
					delta_x =( xCoord(cadr(childid ->bBox)) - xCoord(car(childid ->bBox)))
					delta_y =( yCoord(cadr(childid ->bBox)) - yCoord(car(childid ->bBox)))
					current_aera=delta_x*delta_y

					printf("dx:%f;dy=%f;current_aera=%f;max_aera=%f\n",delta_x,delta_y,current_aera,max_aera)
					if((current_aera > max_aera) then
						 max_aera = current_aera 
						 printf("max_aera=%f\n" , max_aera)
						 sym_x =(xCoord(car(childid ->bBox)) + xCoord(cadr(childid ->bBox))) / 2.0
						 sym_y =(yCoord(car(childid ->bBox)) + yCoord(cadr(childid ->bBox))) / 2.0
					)	


      				);when childid
			);end foreach childid
			halfTextHeight = axlGetParam(sprintf(nil, "paramTextBlock:%d", txt_tblk)) ->height / 2.0
		      case(txt_rot
			(  0, sym_y = sym_y - halfTextHeight)
			( 90, sym_x = sym_x + halfTextHeight)
			(180, sym_y = sym_y + halfTextHeight)
			(270, sym_x = sym_x - halfTextHeight)
		      )
		      xy = list(sym_x, sym_y)
		      changeit = t
		); when CenterAssy
		; ==== Do text movement, if anything has changed ====
		when(changeit
			textOrientation = make_axlTextOrientation( ?textBlock txt_tblk, ?rotation txt_rot, ?mirrored txtObj ->isMirrored, ?justify "CENTER")
			if(axlDBCreateText(text, xy, textOrientation, txtObj ->layer, txtObj ->parent)
			 then axlDeleteObject(txtObj)
			 else axlMsgPut(strcat("Update Failed on ", text))
			)
			printf("%s-%L\n",text,xy)
		)
	); endforeach
)); end defun - rotateSilkAssy

 ;###########################################################
 ;# Form CallBacks - Determine Allegro command to execute   #
 ;#                  based on the user's selection          #
 ;###########################################################

defun( rotateRDForm_Action (form)
	case(form ->curField
		("mediumPrefixes"
			RotateSilkAssyRD_mediumPrefixes = buildString(unique(parseString(upperCase(form ->curValue), " ,")), ",")
			axlFormSetField(form, "mediumPrefixes", RotateSilkAssyRD_mediumPrefixes)
		)
		("smallPrefixes"
			RotateSilkAssyRD_smallPrefixes = buildString(unique(parseString(upperCase(form ->curValue), " ,")), ",")
			axlFormSetField(form, "smallPrefixes", RotateSilkAssyRD_smallPrefixes)
		)
		("apply", DoRotateSilkAssy(form))
    ("cancel", axlFormClose(form), axlCancelEnterFun())
	); end case
); end defun - rotateRDForm_Action


;###########################################################
 ;# createTitleBlockForm - Main User Interface Form         #
 ;#                        Brought up by executing command. #
 ;###########################################################

defun( createRotateRDFormStr ()
	strcat(
		"FILE_TYPE=FORM_DEFN VERSION=2\n"
		"FORM\n"
		"FIXED\n"
		"PORT 77 20\n"
		"HEADER \"Rotate Silkscreen/Assembly Reference Designators V2.2\"\n"
		"TILE\n"

		"GROUP \"Select Layers to Rotate\"\n"
		"GLOC 2 1\n"
		"GSIZE 73 4\n"
		"ENDGROUP\n"

		"FIELD \"SilkTop\"\n"
		"FLOC 3 3 \n"
		"CHECKLIST \"Silkscreen-Top\" \n"
		"ENDFIELD\n"

		"FIELD \"SilkBot\"\n"
		"FLOC 20 3 \n"
		"CHECKLIST \"Silkscreen-Bottom\" \n"
		"ENDFIELD\n"

		"FIELD \"AssyTop\"\n"
		"FLOC 37 3 \n"
		"CHECKLIST \"Assembly-Top\" \n"
		"ENDFIELD\n"

		"FIELD \"AssyBot\"\n"
		"FLOC 54 3 \n"
		"CHECKLIST \"Assembly-Bottom\" \n"
		"ENDFIELD\n"

		"GROUP \"Select Ref Des Orientation\"\n"
		"GLOC 2 5\n"
		"GSIZE 32 13\n"
		"ENDGROUP\n"

		"GROUP \"Ref Des Alterations\"\n"
		"GLOC 36 5\n"
		"GSIZE 39 13\n"
		"ENDGROUP\n"

		"TEXT \"Horizontal           Vertical \"\n"
		"TLOC 6 7 \n"
		"ENDTEXT\n"

		"FIELD \"LRBT\"\n"
		"FLOC 3 9 \n"
		"CHECKLIST \"Left to Right     Bottom to Top\" \"rotate_group\" \n"
		"ENDFIELD\n"

		"FIELD \"LRTB\"\n"
		"FLOC 3 11 \n"
		"CHECKLIST \"Left to Right     Top to Bottom\" \"rotate_group\" \n"
		"ENDFIELD\n"

		"FIELD \"RLBT\"\n"
		"FLOC 3 13 \n"
		"CHECKLIST \"Right to Left     Bottom to Top\" \"rotate_group\" \n"
		"ENDFIELD\n"

		"FIELD \"RLTB\"\n"
		"FLOC 3 15 \n"
		"CHECKLIST \"Right to Left     Top to Bottom\" \"rotate_group\" \n"
		"ENDFIELD\n"

		"FIELD \"CenterAssy\"\n"
		"FLOC 37 7 \n"
		"CHECKLIST \"Center Assembly RDs at Part Origin\" \n"
		"ENDFIELD\n"

		"FIELD \"ChangeTextSize\"\n"
		"FLOC 37 9 \n"
		"CHECKLIST \"Change Text Block Sizes\" \n"
		"ENDFIELD\n"

		"TEXT \"Large  Text Block: \"\n"
		"TLOC 38 11 \n"
		"ENDTEXT\n"

		"TEXT \"Medium Text Block: \"\n"
		"TLOC 38 13 \n"
		"ENDTEXT\n"

		"TEXT \"Small Text Block: \"\n"
		"TLOC 38 15 \n"
		"ENDTEXT\n"

		"FIELD \"TextBlockLarge\"\n"
		"FLOC 53 11 \n"
		"INTSLIDEBAR 3 3\n MIN 1\n MAX 60\n FGROUP\"TxtBlock\" \n"
		"ENDFIELD\n"

		"FIELD \"TextBlockMedium\"\n"
		"FLOC 53 13 \n"
		"INTSLIDEBAR 3 3\n MIN 1\n MAX 60\n FGROUP\"TxtBlock\" \n"
		"ENDFIELD\n"

		"FIELD \"mediumPrefixes\"\n"
		"FLOC 60 13 \n"
		"STRFILLIN 12 99\n"
		"ENDFIELD\n"

		"FIELD \"TextBlockSmall\"\n"
		"FLOC 53 15 \n"
		"INTSLIDEBAR 3 3\n MIN 1\n MAX 60\n FGROUP\"TxtBlock\" \n"
		"ENDFIELD\n"

		"FIELD \"smallPrefixes\"\n"
		"FLOC 60 15 \n"
		"STRFILLIN 12 99\n"
		"ENDFIELD\n"

		"FIELD \"okfixed\"\n"
		"FLOC 3 18 \n"
		"CHECKLIST \"Ignore fixed/locked status\" \n"
		"ENDFIELD\n"

		"FIELD apply\n"
		"FLOC 26 18\n"
		"MENUBUTTON \"Apply\" 6 3\n"
		"ENDFIELD\n"

		"FIELD cancel\n"
		"FLOC 36 18\n"
		"MENUBUTTON \"CANCEL\" 6 3\n"
		"ENDFIELD\n"

		"ENDTILE\n"
		"ENDFORM\n"
  )
)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章