calcCAP_exe.tcl 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984
  1. #! /bin/sh
  2. # restart using wish \
  3. exec /sppdg/software/tools/public_domain/${HOST_TYPE}/bin/wish "$0" "$@"
  4. global curPosition
  5. global openFile
  6. # the number of each kind of conductor and dielectric
  7. global fileHead;
  8. global dieleData recData cirData triData ellData polyData gndData
  9. ### global variables for saving all parameters of each kind
  10. global palFlag
  11. global corFlag
  12. global newFlag
  13. global yesMove
  14. global recCounter cirCounter dieleCounter ellCounter triCounter polyCounter \
  15. gndCounter
  16. global recTags cirTags dieleTags ellTags triTags polyTags gndTags
  17. global recId cirId dieleId ellId triId polyId gndId
  18. global maxXcoord maxYcoord
  19. global paletteXsize paletteYsize Xscale Yscale
  20. global pbottomleftX pbottomleftY
  21. global Nh Nit J
  22. global Nwx Nwy Nws
  23. global Np Eps matr
  24. global pData
  25. global pcal
  26. global od maxga
  27. set fileHead { 0 0 0 0 0 0 0 }; # dieleNum recNum cirNum triNum ellNum polyNum gndNum
  28. set palFlag -1
  29. set corFlag -1; # initially set to new mode
  30. set newFlag -1
  31. set yesMove -1
  32. set curPosition -1
  33. set recCounter 0
  34. set cirCounter 0
  35. set dieleCounter 0
  36. set ellCounter 0
  37. set triCounter 0
  38. set polyCounter 0
  39. set gndCounter 0
  40. set recId ""
  41. set cirId ""
  42. set dieleId ""
  43. set ellId ""
  44. set triId ""
  45. set polyId ""
  46. set gndId ""
  47. set recData ""
  48. set cirData ""
  49. set dieleData ""
  50. set ellData ""
  51. set triData ""
  52. set polyData ""
  53. set gndData ""
  54. set recTags ""
  55. set cirTags ""
  56. set dieleTags ""
  57. set ellTags ""
  58. set triTags ""
  59. set polyTags ""
  60. set gndTags ""
  61. set pData ""
  62. set pcal ""
  63. set maxXcoord 879.00000
  64. set maxYcoord 586.00000
  65. set paletteXsize 0
  66. set paletteYsize 0
  67. set pbottomleftX 0
  68. set pbottomleftY 0
  69. set Xscale 0
  70. set Yscale 0
  71. set Nh 1024
  72. set Nit 40
  73. set J 6
  74. set Nwx 8
  75. set Nwy 10
  76. set Nws 5
  77. set Np 0.0
  78. set Eps 1.0e-5
  79. set matr 2
  80. set od 5
  81. set maxga 0
  82. #########################################################################
  83. #
  84. #
  85. # Capacitance Calculation using Coifman wavelets
  86. # for the method of moments
  87. #
  88. # By Zhichao Zhang
  89. # 2001.5
  90. #
  91. #
  92. #########################################################################
  93. #########################################################################
  94. # NAME: global_init
  95. # PURPOSE: define the global variables which decide the state of
  96. # display mode
  97. #
  98. #########################################################################
  99. proc global_init { } {
  100. global palettebkcolor
  101. createMenu
  102. }
  103. #########################################################################
  104. # NAME: createMenu
  105. # PURPOSE: create the main menu
  106. #
  107. #########################################################################
  108. proc createMenu { } {
  109. frame .mbar -relief raised -bd 2
  110. frame .dummy1 -relief raised -width 20c -height 0.05c -background blue
  111. frame .dummy -width 24c -height 0.5c -background black
  112. #########################################################################
  113. canvas .c -width 24c -height 16c -background black \
  114. -xscrollcommand ".shoriz set" \
  115. -yscrollcommand ".svert set"
  116. scrollbar .svert -orient v -command ".c yview"
  117. scrollbar .shoriz -orient h -command ".c xview"
  118. frame .butt
  119. button .butt.rect -text "Rectangle" -command mkRect -background lightblue -foreground black
  120. button .butt.cir -text "Circle" -command mkCir -background lightblue -foreground black
  121. button .butt.poly -text "Trapezoid" -command mkPoly -background lightblue -foreground black
  122. button .butt.gnd -text "Ground Plate" -command mkGnd -background lightblue -foreground black
  123. button .butt.diele -text "Dieletric" -command mkDiele -background lightblue -foreground black
  124. button .butt.move -text "Move" -command moveUnit -background lightyellow -foreground black
  125. button .butt.delete -text "Delete" -command delUnit -background lightyellow -foreground black
  126. label .dummy.status -text " Status Bar " -background orange
  127. label .dummy.statusCon -text "You are welcome to use this Program!" -background black
  128. button .dummy.eplicon -bitmap @/sppdg/software/bin/hpux10/epl.bit -background black -foreground white -command eplIntro
  129. ##############################################################################
  130. pack .mbar .c .butt .dummy1 .dummy -side top -fill x
  131. pack .butt.rect .butt.cir .butt.poly .butt.gnd .butt.diele -side left
  132. pack .butt.move .butt.delete -side right
  133. pack .dummy.eplicon .dummy.status .dummy.statusCon -side left
  134. menubutton .mbar.file -text File \
  135. -menu .mbar.file.menu
  136. menubutton .mbar.edit -text Edit \
  137. -menu .mbar.edit.menu
  138. menubutton .mbar.setup -text Setup \
  139. -menu .mbar.setup.menu
  140. menubutton .mbar.handcreate -text HandCreate \
  141. -menu .mbar.handcreate.menu
  142. menubutton .mbar.dropcreate -text DropCreate \
  143. -menu .mbar.dropcreate.menu
  144. menubutton .mbar.calculate -text Calculate \
  145. -menu .mbar.calculate.menu
  146. menubutton .mbar.help -text About \
  147. -menu .mbar.help.menu
  148. pack .mbar.file .mbar.edit .mbar.setup \
  149. .mbar.handcreate .mbar.dropcreate .mbar.calculate -side left
  150. pack .mbar.help -side right
  151. menu .mbar.file.menu
  152. .mbar.file.menu add command -label "New" \
  153. -command myAppFileNew
  154. .mbar.file.menu add command -label "Open" \
  155. -command myAppFileOpen
  156. .mbar.file.menu add command -label "Save" \
  157. -command {myAppFileSave $myAppFileName}
  158. .mbar.file.menu add command -label "Save As" \
  159. -command myAppFileSaveAs
  160. .mbar.file.menu add command -label "Close" \
  161. -command myAppFileClose
  162. .mbar.file.menu add separator
  163. .mbar.file.menu add cascade -label "Print" \
  164. -menu .mbar.file.menu.print
  165. .mbar.file.menu add separator
  166. .mbar.file.menu add command -label "Exit" \
  167. -command myAppExit
  168. menu .mbar.file.menu.print
  169. .mbar.file.menu.print add command -label "Geometrical Parameters" -command printPara
  170. .mbar.file.menu.print add command -label "Calculation Parameters" -command printcal
  171. .mbar.file.menu.print add command -label "Print Canvas" -command printGraph
  172. menu .mbar.edit.menu
  173. .mbar.edit.menu add command -label "Move" \
  174. -command moveUnit
  175. .mbar.edit.menu add command -label "Delete" \
  176. -command delUnit
  177. .mbar.edit.menu add separator
  178. .mbar.edit.menu add command -label "Geometry" \
  179. -command editPara
  180. menu .mbar.setup.menu
  181. .mbar.setup.menu add command -label "Option" \
  182. -command \
  183. { Coption .palettePara { Palette Parameters } 0 }
  184. .mbar.setup.menu add command -label "Parameters" \
  185. -command \
  186. { calpara .calPara { Computational Parameters } }
  187. menu .mbar.handcreate.menu
  188. .mbar.handcreate.menu add command -label "Dielectric" \
  189. -command {
  190. set corFlag -1
  191. ## puts $corFlag
  192. dispDiele .dielePara { Dielectric Parameters } {}
  193. }
  194. .mbar.handcreate.menu add command -label "Rectangle" \
  195. -command {
  196. set corFlag -1
  197. ## puts $corFlag
  198. dispRect .rectPara { Rectangular Conductor Parameters } {}
  199. }
  200. .mbar.handcreate.menu add command -label "Circle" \
  201. -command {
  202. set corFlag -1
  203. ## puts $corFlag
  204. dispCir .cirPara { Circular Conductor Parameters } {}
  205. }
  206. .mbar.handcreate.menu add command -label "Trapezoid" \
  207. -command {
  208. set corFlag -1
  209. ## puts $corFlag
  210. getApexnum
  211. }
  212. .mbar.handcreate.menu add command -label "Ground" \
  213. -command {
  214. set corFlag -1
  215. ## puts $corFlag
  216. dispGnd .gndPara { Ground Plane Parameters } {}
  217. }
  218. menu .mbar.dropcreate.menu
  219. .mbar.dropcreate.menu add command -label "Dieletric" \
  220. -command mkDiele
  221. .mbar.dropcreate.menu add command -label "Rectangle" \
  222. -command mkRect
  223. .mbar.dropcreate.menu add command -label "Circle" \
  224. -command mkCir
  225. .mbar.dropcreate.menu add command -label "Trapezoid" \
  226. -command mkPoly
  227. .mbar.dropcreate.menu add command -label "Ground" \
  228. -command mkGnd
  229. menu .mbar.calculate.menu
  230. .mbar.calculate.menu add command -label "Check Data" \
  231. -command { startcal1 1 }
  232. .mbar.calculate.menu add command -label "Start Calculation" \
  233. -command { startcal1 2 }
  234. .mbar.calculate.menu add command -label "Check Results" \
  235. -command { checkResult }
  236. menu .mbar.help.menu
  237. .mbar.help.menu add command -label "About..." \
  238. -command about
  239. .mbar.help.menu add command -label "Readme..." \
  240. -command viewreadme
  241. tk_menuBar .mbar .mbar.file .mbar.edit .mbar.view .mbar.setup \
  242. .mbar.handcreate .mbar.dropcreate .mbar.calculate .mbar.help
  243. focus .mbar
  244. }
  245. #########################################################################
  246. # NAME: editPara
  247. # PURPOSE: edit the parameters of single objects in the palette
  248. #
  249. #########################################################################
  250. proc editPara { } {
  251. global dieleData recData cirData triData ellData polyData gndData
  252. global recTags cirTags dieleTags ellTags triTags polyTags gndTags
  253. global recId cirId dieleId ellId triId polyId gndId
  254. global palFlag
  255. global newFlag
  256. checkPal
  257. if { $palFlag < 0 } {
  258. return $palFlag
  259. }
  260. if { $newFlag < 0 } {
  261. promptInfo "You must setup a new palette first!"
  262. return $newFlag
  263. }
  264. bind .c <Motion> {
  265. set realX [expr { %x/$Xscale+$pbottomleftX }]
  266. set realY [expr { ($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  267. .dummy.statusCon configure -text "x=$realX, y=$realY"
  268. }
  269. bind .c <Button-1> {
  270. set curPoint [.c find withtag current]
  271. ## puts $curPoint
  272. if { [lsearch -exact $recId $curPoint] != -1 } {
  273. setTag $curPoint $recId $recTags $recData
  274. set corFlag 0
  275. ## puts $corFlag
  276. ## puts "current position: $curPosition"
  277. set title "Correct Rectangle No. "
  278. set title1 [lindex $recData [expr { $curPosition+1 }]]
  279. set title $title$title1
  280. dispRect .rectPara $title $curPosition
  281. } elseif { [lsearch -exact $cirId $curPoint] != -1 } {
  282. setTag $curPoint $cirId $cirTags $cirData
  283. set corFlag 0;# set the correcting mode
  284. ## puts $corFlag
  285. set title "Correct Circle No. "
  286. set title1 [lindex $cirData [expr { $curPosition+1 }]]
  287. set title $title$title1
  288. dispCir .cirPara $title $curPosition
  289. } elseif { [lsearch -exact $dieleId $curPoint] != -1 } {
  290. setTag $curPoint $dieleId $dieleTags $dieleData
  291. set corFlag 0;# set the correcting mode
  292. ## puts $corFlag
  293. set title "Correct Dielectric No. "
  294. set title1 [lindex $dieleData [expr { $curPosition+1 }]]
  295. set title $title$title1
  296. dispDiele .dielePara $title $curPosition
  297. } elseif { [lsearch -exact $triId $curPoint] != -1 } {
  298. setTag $curPoint $triId $triTags $triData
  299. set corFlag 0;# set the correcting mode
  300. ## puts $corFlag
  301. set title "Correct Triangle No. "
  302. set title1 [lindex $triData [expr { $curPosition+1 }]]
  303. set title $title$title1
  304. dispTri .triPara $title $curPosition
  305. } elseif { [lsearch -exact $ellId $curPoint] != -1 } {
  306. setTag $curPoint $ellId $ellTags $ellData
  307. set corFlag 0;# set the correcting mode
  308. ## puts $corFlag
  309. set title "Correct Ellipse No. "
  310. set title1 [lindex $ellData [expr { $curPosition+1 }]]
  311. set title $title$title1
  312. dispEll .ellPara $title $curPosition
  313. } elseif { [lsearch -exact $polyId $curPoint] != -1 } {
  314. setTag $curPoint $polyId $polyTags $polyData
  315. set corFlag 0;# set the correcting mode
  316. ## puts $corFlag
  317. set title "Correct Trapezoid No. "
  318. set title1 [lindex $polyData [expr { $curPosition+1 }]]
  319. set title $title$title1
  320. dispPoly .polyPara $title \
  321. [lindex $polyData [expr { $curPosition+2 }]] $curPosition
  322. } elseif { [lsearch -exact $gndId $curPoint] != -1 } {
  323. setTag $curPoint $gndId $gndTags $gndData
  324. set corFlag 0;# set the correcting mode
  325. ## puts $corFlag
  326. set title "Correct Ground No. "
  327. set title1 [lindex $gndData [expr { $curPosition+1 }]]
  328. set title $title$title1
  329. dispGnd .gndPara $title $curPosition
  330. }
  331. }
  332. }
  333. ################################################################################################
  334. # Here below is to draw different shapes
  335. #
  336. ################################################################################################
  337. proc mkRect { } {
  338. global firstnodex firstnodey
  339. global secondnodex secondnodey
  340. global tempnodex tempnodey
  341. global buttonflag
  342. global maxXcoord maxYcoord
  343. global paletteXsize paletteYsize Xscale Yscale
  344. global pbottomleftX pbottomleftY
  345. global palFlag
  346. global newFlag
  347. global myAppChangedFlag
  348. checkPal
  349. if { $palFlag < 0 } {
  350. return $palFlag
  351. }
  352. if { $newFlag < 0 } {
  353. promptInfo "You must setup a new palette first!"
  354. return $newFlag
  355. }
  356. set buttonflag 0
  357. .c config -cursor { cross red white }
  358. bind .c <Motion> {
  359. set realX [expr { %x/$Xscale+$pbottomleftX }]
  360. set realY [expr { ($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  361. ## puts "begin1"
  362. ## puts $pbottomleftY
  363. ## puts $Yscale
  364. ## puts $maxYcoord
  365. ## puts $paletteYsize
  366. ## puts $paletteXsize
  367. ## puts "end1"
  368. .dummy.statusCon configure -text "x=$realX, y=$realY"
  369. if { $buttonflag == 1 } {
  370. .c delete interrect
  371. .c create rectangle $tempnodex $tempnodey %x %y -outline blue \
  372. -tags interrect
  373. }
  374. }
  375. bind .c <Button-1> {
  376. if { $buttonflag == 1 } {
  377. .c delete interrect
  378. incr recCounter
  379. set rect [.c create rectangle $tempnodex $tempnodey %x %y \
  380. -outline white -fill yellow -tags recTags$recCounter ]
  381. lappend recId $rect
  382. lappend recTags recTags$recCounter
  383. ## puts $recTags
  384. set firstnodex($rect) $tempnodex
  385. set firstnodey($rect) $tempnodey
  386. set secondnodex($rect) %x
  387. set secondnodey($rect) %y
  388. ## puts $rect
  389. ## puts $firstnodex($rect)
  390. ## puts $firstnodey($rect)
  391. ## puts $secondnodex($rect)
  392. ## puts $secondnodey($rect)
  393. set buttonflag 0
  394. set fileHead [lreplace $fileHead 1 1 [expr { [lindex $fileHead 1]+1 }]]
  395. ## puts $fileHead
  396. lappend recData "REC"
  397. lappend recData $rect
  398. lappend recData recTags$recCounter
  399. lappend recData $recCounter
  400. if { $firstnodex($rect) <= $secondnodex($rect) } {
  401. set bottomleftX [expr { $firstnodex($rect)/$Xscale+$pbottomleftX }]
  402. } else {
  403. set bottomleftX [expr { $secondnodex($rect)/$Xscale+$pbottomleftX }]
  404. }
  405. if { $firstnodey($rect) >= $secondnodey($rect) } {
  406. set bottomleftY [expr { ($maxYcoord-$firstnodey($rect))/$Yscale+$pbottomleftY }]
  407. } else {
  408. set bottomleftY [expr { ($maxYcoord-$secondnodey($rect))/$Yscale+$pbottomleftY }]
  409. }
  410. lappend recData $bottomleftX
  411. lappend recData $bottomleftY
  412. lappend recData [expr {abs($firstnodex($rect)-$secondnodex($rect))/$Xscale }]
  413. lappend recData [expr {abs($firstnodey($rect)-$secondnodey($rect))/$Yscale }]
  414. set myAppChangedFlag 1
  415. ## puts $recData
  416. } else {
  417. set tempnodex %x
  418. set tempnodey %y
  419. set buttonflag 1
  420. }
  421. }
  422. bind .c <Button-3> {
  423. .c delete interrect
  424. set buttonflag 0
  425. }
  426. return
  427. }
  428. proc mkCir { } {
  429. global firstnodex firstnodey
  430. global secondnodex secondnodey
  431. global tempnodex tempnodey
  432. global buttonflag
  433. global maxXcoord maxYcoord
  434. global paletteXsize paletteYsize Xscale Yscale
  435. global pbottomleftX pbottomleftY
  436. global palFlag newFlag
  437. global myAppChangedFlag
  438. checkPal
  439. if { $palFlag < 0 } {
  440. return $palFlag
  441. }
  442. if { $newFlag < 0 } {
  443. promptInfo "You must setup a new palette first!"
  444. return $newFlag
  445. }
  446. .c config -cursor { cross red white }
  447. set buttonflag 0
  448. bind .c <Motion> {
  449. ## puts "(%x %y)"
  450. set realX [expr {%x/$Xscale+$pbottomleftX }]
  451. set realY [expr {($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  452. .dummy.statusCon configure -text "x=$realX, y=$realY"
  453. if { $buttonflag == 1 } {
  454. .c delete interrect
  455. set radius [expr {hypot(($tempnodex-%x),($tempnodey-%y)) }]
  456. ## puts $radius
  457. .c create oval [expr {$tempnodex-$radius }] [expr {$tempnodey-$radius }]\
  458. [expr {$tempnodex+$radius }] [expr {$tempnodey+$radius }] -outline blue -tags interrect
  459. }
  460. }
  461. bind .c <Button-1> {
  462. if { $buttonflag == 1 } {
  463. .c delete interrect
  464. set radius [expr {hypot(($tempnodex-%x),($tempnodey-%y)) }]
  465. ## puts $radius
  466. incr cirCounter
  467. set cir [.c create oval [expr {$tempnodex-$radius }] [expr {$tempnodey-$radius }] \
  468. [expr {$tempnodex+$radius }] [expr {$tempnodey+$radius }] \
  469. -outline white -fill red -tags cirTags$cirCounter]
  470. lappend cirId $cir
  471. lappend cirTags cirTags$cirCounter
  472. set firstnodex($cir) $tempnodex
  473. set firstnodey($cir) $tempnodey
  474. set secondnodex($cir) %x
  475. set secondnodey($cir) %y
  476. ## puts $cir
  477. ## puts $firstnodex($cir)
  478. ## puts $firstnodey($cir)
  479. ## puts $secondnodex($cir)
  480. ## puts $secondnodey($cir)
  481. set buttonflag 0
  482. set fileHead [lreplace $fileHead 2 2 [expr {[lindex $fileHead 2]+1 }]]
  483. ## puts $fileHead
  484. lappend cirData "CIR"
  485. lappend cirData $cir
  486. lappend cirData cirTags$cirCounter
  487. lappend cirData $cirCounter
  488. lappend cirData [expr {$firstnodex($cir)/$Xscale+$pbottomleftX }]
  489. lappend cirData [expr {($maxYcoord-$firstnodey($cir))/$Yscale+$pbottomleftY }]
  490. lappend cirData [expr {hypot(($firstnodex($cir)-$secondnodex($cir))/$Xscale, \
  491. ($firstnodey($cir)-$secondnodey($cir))/$Yscale) }]
  492. set myAppChangedFlag 1
  493. ## puts $cirData
  494. } else {
  495. set tempnodex %x
  496. set tempnodey %y
  497. set buttonflag 1
  498. }
  499. }
  500. bind .c <Button-3> {
  501. .c delete interrect
  502. set buttonflag 0
  503. }
  504. return
  505. }
  506. proc mkDiele { } {
  507. global firstnodex firstnodey
  508. global secondnodex secondnodey
  509. global tempnodex tempnodey
  510. global buttonflag
  511. global maxXcoord maxYcoord
  512. global paletteXsize paletteYsize Xscale Yscale
  513. global pbottomleftX pbottomleftY
  514. global palFlag newFlag
  515. global myAppChangedFlag
  516. global maxga
  517. checkPal
  518. if { $palFlag < 0 } {
  519. return $palFlag
  520. }
  521. if { $newFlag < 0 } {
  522. promptInfo "You must setup a new palette first!"
  523. return $newFlag
  524. }
  525. .c config -cursor { cross red white }
  526. set buttonflag 0
  527. bind .c <Motion> {
  528. ## puts "(%x %y)"
  529. set realX [expr {%x/$Xscale+$pbottomleftX }]
  530. set realY [expr {($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  531. .dummy.statusCon configure -text "x=$realX, y=$realY"
  532. if { $buttonflag == 1 } {
  533. .c delete interrect
  534. .c create rectangle $tempnodex $tempnodey %x %y -outline blue \
  535. -tags interrect
  536. }
  537. }
  538. bind .c <Button-1> {
  539. if { $buttonflag == 1 } {
  540. .c delete interrect
  541. incr dieleCounter
  542. set diele [.c create rectangle $tempnodex $tempnodey %x %y \
  543. -outline white -fill black -tags dieleTags$dieleCounter]
  544. lappend dieleId $diele
  545. lappend dieleTags dieleTags$dieleCounter
  546. .c lower $diele
  547. set firstnodex($diele) $tempnodex
  548. set firstnodey($diele) $tempnodey
  549. set secondnodex($diele) %x
  550. set secondnodey($diele) %y
  551. ## puts $diele
  552. ## puts $firstnodex($diele)
  553. ## puts $firstnodey($diele)
  554. ## puts $secondnodex($diele)
  555. ## puts $secondnodey($diele)
  556. set buttonflag 0
  557. set fileHead [lreplace $fileHead 0 0 [expr {[lindex $fileHead 0]+1 }]]
  558. ## puts $fileHead
  559. lappend dieleData "DIELE"
  560. lappend dieleData $diele
  561. lappend dieleData dieleTags$dieleCounter
  562. lappend dieleData $dieleCounter
  563. if { $firstnodex($diele) <= $secondnodex($diele) } {
  564. set bottomleftX [expr {$firstnodex($diele)/$Xscale+$pbottomleftX }]
  565. } else {
  566. set bottomleftX [expr {$secondnodex($diele)/$Xscale+$pbottomleftX }]
  567. }
  568. if { $firstnodey($diele) >= $secondnodey($diele) } {
  569. set bottomleftY [expr {($maxYcoord-$firstnodey($diele))/$Yscale+$pbottomleftY }]
  570. } else {
  571. set bottomleftY [expr {($maxYcoord-$secondnodey($diele))/$Yscale+$pbottomleftY }]
  572. }
  573. lappend dieleData $bottomleftX
  574. lappend dieleData $bottomleftY
  575. lappend dieleData [expr {abs($firstnodex($diele)-$secondnodex($diele))/$Xscale }]
  576. lappend dieleData [expr {abs($firstnodey($diele)-$secondnodey($diele))/$Yscale }]
  577. if { [expr {1.0/(abs($firstnodey($diele)-$secondnodey($diele))/$Yscale) }] > $maxga } {
  578. set maxga [expr {1.0/(abs($firstnodey($diele)-$secondnodey($diele))/$Yscale) }]
  579. }
  580. lappend dieleData 1.0 ; #permitivity
  581. set myAppChangedFlag 1
  582. ## puts $dieleData
  583. } else {
  584. set tempnodex %x
  585. set tempnodey %y
  586. set buttonflag 1
  587. }
  588. }
  589. bind .c <Button-3> {
  590. .c delete interrect
  591. set buttonflag 0
  592. }
  593. return
  594. }
  595. proc mkGnd { } {
  596. global firstnodex firstnodey
  597. global secondnodex secondnodey
  598. global tempnodex tempnodey
  599. global buttonflag
  600. global maxXcoord maxYcoord
  601. global paletteXsize paletteYsize Xscale Yscale
  602. global pbottomleftX pbottomleftY
  603. global palFlag newFlag
  604. global myAppChangedFlag
  605. checkPal
  606. if { $palFlag < 0 } {
  607. return $palFlag
  608. }
  609. if { $newFlag < 0 } {
  610. promptInfo "You must setup a new palette first!"
  611. return $newFlag
  612. }
  613. .c config -cursor { cross red white }
  614. set buttonflag 0
  615. bind .c <Motion> {
  616. ## puts "(%x %y)"
  617. set realX [expr {%x/$Xscale+$pbottomleftX }]
  618. set realY [expr {($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  619. .dummy.statusCon configure -text "x=$realX, y=$realY"
  620. if { $buttonflag == 1 } {
  621. .c delete interrect
  622. .c create rectangle $tempnodex $tempnodey %x %y -outline blue \
  623. -tags interrect
  624. }
  625. }
  626. bind .c <Button-1> {
  627. if { $buttonflag == 1 } {
  628. .c delete interrect
  629. incr gndCounter
  630. set gnd [.c create rectangle $tempnodex $tempnodey %x %y \
  631. -outline white -fill green -tags gndTags$gndCounter]
  632. lappend gndId $gnd
  633. lappend gndTags gndTags$gndCounter
  634. set firstnodex($gnd) $tempnodex
  635. set firstnodey($gnd) $tempnodey
  636. set secondnodex($gnd) %x
  637. set secondnodey($gnd) %y
  638. ## puts $gnd
  639. ## puts $firstnodex($gnd)
  640. ## puts $firstnodey($gnd)
  641. ## puts $secondnodex($gnd)
  642. ## puts $secondnodey($gnd)
  643. set buttonflag 0
  644. set fileHead [lreplace $fileHead 6 6 [expr {[lindex $fileHead 6]+1 }]]
  645. ## puts $fileHead
  646. lappend gndData "GND"
  647. lappend gndData $gnd
  648. lappend gndData gndTags$gndCounter
  649. lappend gndData $gndCounter
  650. if { $firstnodex($gnd) <= $secondnodex($gnd) } {
  651. set bottomleftX [expr {$firstnodex($gnd)/$Xscale+$pbottomleftX }]
  652. } else {
  653. set bottomleftX [expr {$secondnodex($gnd)/$Xscale+$pbottomleftX }]
  654. }
  655. if { $firstnodey($gnd) >= $secondnodey($gnd) } {
  656. set bottomleftY [expr {($maxYcoord-$firstnodey($gnd))/$Yscale+$pbottomleftY }]
  657. } else {
  658. set bottomleftY [expr {($maxYcoord-$secondnodey($gnd))/$Yscale+$pbottomleftY }]
  659. }
  660. lappend gndData $bottomleftX
  661. lappend gndData $bottomleftY
  662. lappend gndData [expr {abs($firstnodex($gnd)-$secondnodex($gnd))/$Xscale }]
  663. lappend gndData [expr {abs($firstnodey($gnd)-$secondnodey($gnd))/$Yscale }]
  664. set myAppChangedFlag 1
  665. ## puts $gndData
  666. } else {
  667. set tempnodex %x
  668. set tempnodey %y
  669. set buttonflag 1
  670. }
  671. }
  672. bind .c <Button-3> {
  673. .c delete interrect
  674. set buttonflag 0
  675. }
  676. return
  677. }
  678. proc mkTri { } {
  679. global firstnodex firstnodey
  680. global secondnodex secondnodey
  681. global thirdnodex thirdnodey
  682. global tempnodex tempnodey
  683. global tempnodex2 tempnodey2
  684. global buttonflag
  685. global maxXcoord maxYcoord
  686. global paletteXsize paletteYsize Xscale Yscale
  687. global pbottomleftX pbottomleftY
  688. global palFlag newFlag
  689. global myAppChangedFlag
  690. checkPal
  691. if { $palFlag < 0 } {
  692. return $palFlag
  693. }
  694. if { $newFlag < 0 } {
  695. promptInfo "You must setup a new palette first!"
  696. return $newFlag
  697. }
  698. .c config -cursor { cross red white }
  699. set buttonflag 0
  700. bind .c <Motion> {
  701. ## puts "(%x %y)"
  702. set realX [expr {%x/$Xscale+$pbottomleftX }]
  703. set realY [expr {($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  704. .dummy.statusCon configure -text "x=$realX, y=$realY"
  705. if { $buttonflag == 1 } {
  706. .c delete interrect
  707. .c create line $tempnodex $tempnodey %x %y \
  708. -tags interrect
  709. } elseif { $buttonflag == 2 } {
  710. .c delete interrect
  711. .c create polygon $tempnodex $tempnodey $tempnodex2 $tempnodey2 %x %y \
  712. -outline blue -tags interrect
  713. }
  714. }
  715. bind .c <Button-1> {
  716. if { $buttonflag == 2 } {
  717. .c delete interrect
  718. incr triCounter
  719. set tri [.c create polygon $tempnodex $tempnodey \
  720. $tempnodex2 $tempnodey2 %x %y \
  721. -outline black -fill white -tags triTags$triCounter]
  722. lappend triId $tri
  723. lappend triTags triTags$triCounter
  724. set firstnodex($tri) $tempnodex
  725. set firstnodey($tri) $tempnodey
  726. set secondnodex($tri) $tempnodex2
  727. set secondnodey($tri) $tempnodey2
  728. set thirdnodex($tri) %x
  729. set thirdnodey($tri) %y
  730. ## puts $tri
  731. ## puts $firstnodex($tri)
  732. ## puts $firstnodey($tri)
  733. ## puts $secondnodex($tri)
  734. ## puts $secondnodey($tri)
  735. ## puts $thirdnodex($tri)
  736. ## puts $thirdnodey($tri)
  737. set buttonflag 0
  738. set fileHead [lreplace $fileHead 3 3 [expr {[lindex $fileHead 3]+1 }]]
  739. ## puts $fileHead
  740. lappend triData "TRI"
  741. lappend triData $tri
  742. lappend triData triTags$triCounter
  743. lappend triData $triCounter
  744. lappend triData [expr {$firstnodex($tri)/$Xscale+$pbottomleftX }]
  745. lappend triData [expr {($maxYcoord-$firstnodey($tri))/$Yscale+$pbottomleftY }]
  746. lappend triData [expr {$secondnodex($tri)/$Xscale+$pbottomleftX }]
  747. lappend triData [expr {($maxYcoord-$secondnodey($tri))/$Yscale+$pbottomleftY }]
  748. lappend triData [expr {$thirdnodex($tri)/$Xscale+$pbottomleftX }]
  749. lappend triData [expr {($maxYcoord-$thirdnodey($tri))/$Yscale+$pbottomleftY }]
  750. set myAppChangedFlag 1
  751. ## puts $triData
  752. } elseif { $buttonflag == 1 } {
  753. .c delete interrect
  754. .c create line $tempnodex $tempnodey %x %y \
  755. -tags interrect
  756. set tempnodex2 %x
  757. set tempnodey2 %y
  758. set buttonflag 2
  759. } else {
  760. set tempnodex %x
  761. set tempnodey %y
  762. set buttonflag 1
  763. }
  764. }
  765. bind .c <Button-3> {
  766. .c delete interrect
  767. set buttonflag 0
  768. }
  769. return
  770. }
  771. proc mkEll { } {
  772. global firstnodex firstnodey
  773. global secondnodex secondnodey
  774. global tempnodex tempnodey
  775. global buttonflag
  776. global maxXcoord maxYcoord
  777. global paletteXsize paletteYsize Xscale Yscale
  778. global pbottomleftX pbottomleftY
  779. global palFlag newFlag
  780. global myAppChangedFlag
  781. checkPal
  782. if { $palFlag < 0 } {
  783. return $palFlag
  784. }
  785. if { $newFlag < 0 } {
  786. promptInfo "You must setup a new palette first!"
  787. return $newFlag
  788. }
  789. .c config -cursor { cross red white }
  790. set buttonflag 0
  791. bind .c <Motion> {
  792. ## puts "(%x %y)"
  793. set realX [expr {%x/$Xscale+$pbottomleftX }]
  794. set realY [expr {($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  795. .dummy.statusCon configure -text "x=$realX, y=$realY"
  796. if { $buttonflag == 1 } {
  797. .c delete interrect
  798. set majoraxis [expr {sqrt(2)*($tempnodex-%x) }]
  799. set minoraxis [expr {sqrt(2)*($tempnodey-%y) }]
  800. .c create oval [expr {$tempnodex-$majoraxis }] [expr {$tempnodey-$minoraxis }] \
  801. [expr {$tempnodex+$majoraxis }] [expr {$tempnodey+$minoraxis }] \
  802. -outline blue -tags interrect
  803. }
  804. }
  805. bind .c <Button-1> {
  806. if { $buttonflag == 1 } {
  807. .c delete interrect
  808. set majoraxis [expr {sqrt(2)*($tempnodex-%x) }]
  809. set minoraxis [expr {sqrt(2)*($tempnodey-%y) }]
  810. incr ellCounter
  811. set ell [.c create oval [expr {$tempnodex-$majoraxis }] [expr {$tempnodey-$minoraxis }] \
  812. [expr {$tempnodex+$majoraxis }] [expr {$tempnodey+$minoraxis }] \
  813. -outline black -fill white -tags ellTags$ellCounter]
  814. lappend ellId $ell
  815. lappend ellTags ellTags$ellCounter
  816. set firstnodex($ell) $tempnodex
  817. set firstnodey($ell) $tempnodey
  818. set secondnodex($ell) %x
  819. set secondnodey($ell) %y
  820. ## puts $ell
  821. ## puts $firstnodex($ell)
  822. ## puts $firstnodey($ell)
  823. ## puts $secondnodex($ell)
  824. ## puts $secondnodey($ell)
  825. set buttonflag 0
  826. set fileHead [lreplace $fileHead 4 4 [expr {[lindex $fileHead 4]+1 }]]
  827. ## puts $fileHead
  828. lappend ellData "ELL"
  829. lappend ellData $ell
  830. lappend ellData ellTags$ellCounter
  831. lappend ellData $ellCounter
  832. lappend ellData [expr {$firstnodex($ell)/$Xscale+$pbottomleftX }]
  833. lappend ellData [expr {($maxYcoord-$firstnodey($ell))/$Yscale+$pbottomleftY }]
  834. lappend ellData [expr {abs($majoraxis)/$Xscale }]
  835. lappend ellData [expr {abs($minoraxis)/$Yscale }]
  836. set myAppChangedFlag 1
  837. ## puts $ellData
  838. } else {
  839. set tempnodex %x
  840. set tempnodey %y
  841. set buttonflag 1
  842. }
  843. }
  844. bind .c <Button-3> {
  845. .c delete interrect
  846. set buttonflag 0
  847. }
  848. return
  849. }
  850. proc mkPoly { } {
  851. global apexnum
  852. global xcoord ycoord xycoord
  853. global apexorder
  854. global tempnodex tempnodey
  855. global tempnodex2 tempnodey2
  856. global buttonflag
  857. global maxXcoord maxYcoord
  858. global paletteXsize paletteYsize Xscale Yscale
  859. global pbottomleftX pbottomleftY
  860. global palFlag newFlag
  861. global myAppChangedFlag
  862. checkPal
  863. if { $palFlag < 0 } {
  864. return $palFlag
  865. }
  866. if { $newFlag < 0 } {
  867. promptInfo "You must setup a new palette first!"
  868. return $newFlag
  869. }
  870. getApexnumdrop
  871. set buttonflag 0
  872. set apexorder 0
  873. .c config -cursor { cross red white }
  874. bind .c <Motion> {
  875. ## puts "(%x %y)"
  876. set realX [expr {%x/$Xscale+$pbottomleftX }]
  877. set realY [expr {($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  878. .dummy.statusCon configure -text "x=$realX, y=$realY"
  879. if { $apexorder > 0 && $apexorder < $apexnum } {
  880. .c delete curside
  881. .c create line [lindex $xcoord [expr {$apexorder-1 }]] \
  882. [lindex $ycoord [expr {$apexorder-1 }]] %x %y -tags curside
  883. }
  884. }
  885. bind .c <Button-1> {
  886. if { $apexorder == 0 } {
  887. set xcoord %x
  888. set ycoord %y
  889. set xycoord %x
  890. lappend xycoord %y
  891. incr apexorder
  892. } elseif { $apexorder > 0 && $apexorder < [expr {$apexnum-1 }] } {
  893. lappend xcoord %x
  894. lappend ycoord %y
  895. lappend xycoord %x
  896. lappend xycoord %y
  897. incr apexorder
  898. .c delete interrect
  899. set counter 0
  900. while { $counter < [expr {$apexorder-1 }] } {
  901. ## puts $counter
  902. ## puts $apexorder
  903. ## puts [lindex $xcoord $counter]
  904. ## puts [lindex $ycoord $counter]
  905. ## puts [lindex $xcoord [expr {$counter+1 }]]
  906. ## puts [lindex $ycoord [expr {$counter+1 }]]
  907. ## puts $xcoord
  908. ## puts $ycoord
  909. ## puts $xycoord
  910. .c create line [lindex $xcoord $counter] [lindex $ycoord $counter] \
  911. [lindex $xcoord [expr {$counter+1 }]] [lindex $ycoord [expr {$counter+1 }]] \
  912. -tags interrect
  913. incr counter
  914. }
  915. } elseif { $apexorder == [expr {$apexnum-1 }] } {
  916. lappend xcoord %x
  917. lappend ycoord %y
  918. lappend xycoord %x
  919. lappend xycoord %y
  920. .c delete interrect
  921. .c delete curside
  922. incr polyCounter
  923. set poly [.c create polygon $xycoord -outline white -fill \
  924. blue -tags polyTags$polyCounter]
  925. lappend polyId $poly
  926. lappend polyTags polyTags$polyCounter
  927. set buttonflag 0
  928. set apexorder 0
  929. set fileHead [lreplace $fileHead 5 5 [expr {[lindex $fileHead 5]+1 }]]
  930. ## puts $fileHead
  931. lappend polyData "POLY"
  932. lappend polyData $poly
  933. lappend polyData polyTags$polyCounter
  934. lappend polyData $polyCounter
  935. lappend polyData [expr {[llength $xycoord]/2 }]
  936. ## puts [llength $xycoord]
  937. for {set i 0} {$i < [expr {[llength $xycoord]/2 }]} {incr i} {
  938. lappend polyData [expr {[lindex $xycoord [expr {2*$i }]]/$Xscale+$pbottomleftX }]
  939. lappend polyData [expr {($maxYcoord-[lindex $xycoord [expr {2*$i+1 }]])/$Yscale \
  940. +$pbottomleftY }]
  941. }
  942. set myAppChangedFlag 1
  943. ## puts $polyData
  944. }
  945. }
  946. bind .c <Button-3> {
  947. .c delete interrect
  948. .c delete curside
  949. set buttonflag 0
  950. set apexorder 0
  951. }
  952. return
  953. }
  954. #########################################################################################
  955. # Move Unit
  956. #
  957. #########################################################################################
  958. proc moveUnit { } {
  959. global dieleData recData cirData triData ellData polyData gndData
  960. global maxXcoord maxYcoord
  961. global paletteXsize paletteYsize Xscale Yscale
  962. global pbottomleftX pbottomleftY
  963. global newFlag
  964. global myAppChangedFlag
  965. if { $newFlag < 0 } {
  966. promptInfo "You must setup a new palette first!"
  967. return $newFlag
  968. }
  969. bind .c <Button-1> {
  970. if { [lsearch -exact $recId $curPoint] != -1
  971. || [lsearch -exact $cirId $curPoint] != -1
  972. || [lsearch -exact $dieleId $curPoint] != -1
  973. || [lsearch -exact $ellId $curPoint] != -1
  974. || [lsearch -exact $triId $curPoint] != -1
  975. || [lsearch -exact $polyId $curPoint] != -1
  976. || [lsearch -exact $gndId $curPoint] != -1 } {
  977. set curX %x
  978. set curY %y
  979. set oriX %x
  980. set oriY %y
  981. } else {}
  982. }
  983. bind .c <B1-Motion> {
  984. set curPoint [.c find withtag current]
  985. ## puts $curPoint
  986. if { [lsearch -exact $recId $curPoint] != -1
  987. || [lsearch -exact $cirId $curPoint] != -1
  988. || [lsearch -exact $dieleId $curPoint] != -1
  989. || [lsearch -exact $ellId $curPoint] != -1
  990. || [lsearch -exact $triId $curPoint] != -1
  991. || [lsearch -exact $polyId $curPoint] != -1
  992. || [lsearch -exact $gndId $curPoint] != -1 } {
  993. ## puts "(%x %y)"
  994. set realX [expr {%x/$Xscale+$pbottomleftX }]
  995. set realY [expr {($maxYcoord-%y)/$Yscale+$pbottomleftY }]
  996. set deltaX [expr {(%x-$oriX)/$Xscale }]
  997. set deltaY [expr {($oriY-%y)/$Yscale }]
  998. .dummy.statusCon configure -text "x=$realX, y=$realY, dx=$deltaX, dy=$deltaY"
  999. ## puts $recId
  1000. ## puts [lsearch -exact $recId $curPoint]
  1001. if { [lsearch -exact $recId $curPoint] != -1 } {
  1002. ## puts [lsearch -exact $recId $curPoint]
  1003. ## puts [lindex $recTags [lsearch -exact $recId $curPoint]]
  1004. .c move [lindex $recTags [lsearch -exact $recId $curPoint]] \
  1005. [expr {%x-$curX }] [expr {%y-$curY }]
  1006. .c raise [lindex $recTags [lsearch -exact $recId $curPoint]]; #ensure on top of diele
  1007. # the data of position should be changed and saved after movement
  1008. set curX %x
  1009. set curY %y
  1010. bind .c <ButtonRelease-1> {
  1011. setTag $curPoint $recId $recTags $recData
  1012. set xnew [expr {(%x-$oriX)/$Xscale }]
  1013. set ynew [expr {(%y-$oriY)/$Yscale }]
  1014. set recData [lreplace $recData [expr {$curPosition+2 }] [expr {$curPosition+2 }] \
  1015. [expr {[lindex $recData [expr {$curPosition+2 }]]+$xnew }]]
  1016. set recData [lreplace $recData [expr {$curPosition+3 }] [expr {$curPosition+3 }] \
  1017. [expr {[lindex $recData [expr {$curPosition+3 }]]-$ynew }]]
  1018. set myAppChangedFlag 1
  1019. bind .c <Button-1> { }
  1020. bind .c <B1-Motion> { }
  1021. bind .c <ButtonRelease-1> { }
  1022. }
  1023. } elseif { [lsearch -exact $cirId $curPoint] != -1 } {
  1024. ## puts [lsearch -exact $cirId $curPoint]
  1025. ## puts [lindex $cirTags [lsearch -exact $cirId $curPoint]]
  1026. .c move [lindex $cirTags [lsearch -exact $cirId $curPoint]] \
  1027. [expr {%x-$curX }] [expr {%y-$curY }]
  1028. .c raise [lindex $cirTags [lsearch -exact $cirId $curPoint]]
  1029. set curX %x
  1030. set curY %y
  1031. bind .c <ButtonRelease-1> {
  1032. setTag $curPoint $cirId $cirTags $cirData
  1033. set xnew [expr {(%x-$oriX)/$Xscale }]
  1034. set ynew [expr {(%y-$oriY)/$Yscale }]
  1035. set cirData [lreplace $cirData [expr {$curPosition+2 }] [expr {$curPosition+2 }] \
  1036. [expr {[lindex $cirData [expr {$curPosition+2 }]]+$xnew }]]
  1037. set cirData [lreplace $cirData [expr {$curPosition+3 }] [expr {$curPosition+3 }] \
  1038. [expr {[lindex $cirData [expr {$curPosition+3 }]]-$ynew }]]
  1039. set myAppChangedFlag 1
  1040. bind .c <Button-1> { }
  1041. bind .c <B1-Motion> { }
  1042. bind .c <ButtonRelease-1> { }
  1043. }
  1044. } elseif { [lsearch -exact $dieleId $curPoint] != -1 } {
  1045. ## puts [lsearch -exact $dieleId $curPoint]
  1046. ## puts [lindex $dieleTags [lsearch -exact $dieleId $curPoint]]
  1047. .c move [lindex $dieleTags [lsearch -exact $dieleId $curPoint]] \
  1048. [expr {%x-$curX }] [expr {%y-$curY }]
  1049. .c lower [lindex $dieleTags [lsearch -exact $dieleId $curPoint]]
  1050. set curX %x
  1051. set curY %y
  1052. bind .c <ButtonRelease-1> {
  1053. setTag $curPoint $dieleId $dieleTags $dieleData
  1054. set xnew [expr {(%x-$oriX)/$Xscale }]
  1055. set ynew [expr {(%y-$oriY)/$Yscale }]
  1056. set dieleData [lreplace $dieleData [expr {$curPosition+2 }] [expr {$curPosition+2 }] \
  1057. [expr {[lindex $dieleData [expr {$curPosition+2 }]]+$xnew }]]
  1058. set dieleData [lreplace $dieleData [expr {$curPosition+3 }] [expr {$curPosition+3 }] \
  1059. [expr {[lindex $dieleData [expr {$curPosition+3 }]]-$ynew }]]
  1060. set myAppChangedFlag 1
  1061. bind .c <Button-1> { }
  1062. bind .c <B1-Motion> { }
  1063. bind .c <ButtonRelease-1> { }
  1064. }
  1065. } elseif { [lsearch -exact $ellId $curPoint] != -1 } {
  1066. ## puts [lsearch -exact $ellId $curPoint]
  1067. ## puts [lindex $ellTags [lsearch -exact $ellId $curPoint]]
  1068. .c move [lindex $ellTags [lsearch -exact $ellId $curPoint]] \
  1069. [expr {%x-$curX }] [expr {%y-$curY }]
  1070. .c raise [lindex $ellTags [lsearch -exact $ellId $curPoint]]
  1071. set curX %x
  1072. set curY %y
  1073. bind .c <ButtonRelease-1> {
  1074. setTag $curPoint $ellId $ellTags $ellData
  1075. set xnew [expr {(%x-$oriX)/$Xscale }]
  1076. set ynew [expr {(%y-$oriY)/$Yscale }]
  1077. set ellData [lreplace $ellData [expr {$curPosition+2 }] [expr {$curPosition+2 }] \
  1078. [expr {[lindex $ellData [expr {$curPosition+2 }]]+$xnew }]]
  1079. set ellData [lreplace $ellData [expr {$curPosition+3 }] [expr {$curPosition+3 }] \
  1080. [expr {[lindex $ellData [expr {$curPosition+3 }]]-$ynew }]]
  1081. set myAppChangedFlag 1
  1082. bind .c <Button-1> { }
  1083. bind .c <B1-Motion> { }
  1084. bind .c <ButtonRelease-1> { }
  1085. }
  1086. } elseif { [lsearch -exact $triId $curPoint] != -1 } {
  1087. ## puts [lsearch -exact $triId $curPoint]
  1088. ## puts [lindex $triTags [lsearch -exact $triId $curPoint]]
  1089. .c move [lindex $triTags [lsearch -exact $triId $curPoint]] \
  1090. [expr {%x-$curX }] [expr {%y-$curY }]
  1091. .c raise [lindex $triTags [lsearch -exact $triId $curPoint]]
  1092. set curX %x
  1093. set curY %y
  1094. bind .c <ButtonRelease-1> {
  1095. setTag $curPoint $triId $triTags $triData
  1096. set xnew [expr {(%x-$oriX)/$Xscale }]
  1097. set ynew [expr {(%y-$oriY)/$Yscale }]
  1098. set triData [lreplace $triData [expr {$curPosition+2 }] [expr {$curPosition+2 }] \
  1099. [expr {[lindex $triData [expr {$curPosition+2 }]]+$xnew }]]
  1100. set triData [lreplace $triData [expr {$curPosition+3 }] [expr {$curPosition+3 }] \
  1101. [expr {[lindex $triData [expr {$curPosition+3 }]]-$ynew }]]
  1102. set triData [lreplace $triData [expr {$curPosition+4 }] [expr {$curPosition+4 }] \
  1103. [expr {[lindex $triData [expr {$curPosition+4 }]]+$xnew }]]
  1104. set triData [lreplace $triData [expr {$curPosition+5 }] [expr {$curPosition+5 }] \
  1105. [expr {[lindex $triData [expr {$curPosition+5 }]]-$ynew }]]
  1106. set triData [lreplace $triData [expr {$curPosition+6 }] [expr {$curPosition+6 }] \
  1107. [expr {[lindex $triData [expr {$curPosition+6 }]]+$xnew }]]
  1108. set triData [lreplace $triData [expr {$curPosition+7 }] [expr {$curPosition+7 }] \
  1109. [expr {[lindex $triData [expr {$curPosition+7 }]]-$ynew }]]
  1110. set myAppChangedFlag 1
  1111. bind .c <Button-1> { }
  1112. bind .c <B1-Motion> { }
  1113. bind .c <ButtonRelease-1> { }
  1114. }
  1115. } elseif { [lsearch -exact $polyId $curPoint] != -1 } {
  1116. ## puts [lsearch -exact $polyId $curPoint]
  1117. ## puts [lindex $polyTags [lsearch -exact $polyId $curPoint]]
  1118. .c move [lindex $polyTags [lsearch -exact $polyId $curPoint]] \
  1119. [expr {%x-$curX }] [expr {%y-$curY }]
  1120. .c raise [lindex $polyTags [lsearch -exact $polyId $curPoint]]
  1121. set curX %x
  1122. set curY %y
  1123. bind .c <ButtonRelease-1> {
  1124. setTag $curPoint $polyId $polyTags $polyData
  1125. set apex [lindex $polyData [expr {$curPosition+2 }]]
  1126. set xnew [expr {(%x-$oriX)/$Xscale }]
  1127. set ynew [expr {(%y-$oriY)/$Yscale }]
  1128. for {set polycounter 1} {$polycounter<=$apex} {incr polycounter} {
  1129. set tempx [expr {$curPosition+2*$polycounter+1 }]
  1130. set tempy [expr {$curPosition+2*$polycounter+2 }]
  1131. set polyData [lreplace $polyData $tempx $tempx \
  1132. [expr {[lindex $polyData $tempx]+$xnew }]]
  1133. set polyData [lreplace $polyData $tempy $tempy \
  1134. [expr {[lindex $polyData $tempy]-$ynew }]]
  1135. set myAppChangedFlag 1
  1136. bind .c <Button-1> { }
  1137. bind .c <B1-Motion> { }
  1138. bind .c <ButtonRelease-1> { }
  1139. }
  1140. }
  1141. } elseif { [lsearch -exact $gndId $curPoint] != -1 } {
  1142. ## puts [lsearch -exact $gndId $curPoint]
  1143. ## puts [lindex $gndTags [lsearch -exact $gndId $curPoint]]
  1144. .c move [lindex $gndTags [lsearch -exact $gndId $curPoint]] \
  1145. [expr {%x-$curX }] [expr {%y-$curY }]
  1146. .c raise [lindex $gndTags [lsearch -exact $gndId $curPoint]]
  1147. set curX %x
  1148. set curY %y
  1149. bind .c <ButtonRelease-1> {
  1150. setTag $curPoint $gndId $gndTags $gndData
  1151. set xnew [expr {(%x-$oriX)/$Xscale }]
  1152. set ynew [expr {(%y-$oriY)/$Yscale }]
  1153. set gndData [lreplace $gndData [expr {$curPosition+2 }] [expr {$curPosition+2 }] \
  1154. [expr {[lindex $gndData [expr {$curPosition+2 }]]+$xnew }]]
  1155. set gndData [lreplace $gndData [expr {$curPosition+3 }] [expr {$curPosition+3 }] \
  1156. [expr {[lindex $gndData [expr {$curPosition+3 }]]-$ynew }]]
  1157. set myAppChangedFlag 1
  1158. bind .c <Button-1> { }
  1159. bind .c <B1-Motion> { }
  1160. bind .c <ButtonRelease-1> { }
  1161. }
  1162. } else {
  1163. bind .c <Button-1> { }
  1164. bind .c <B1-Motion> { }
  1165. bind .c <ButtonRelease-1> { }
  1166. }
  1167. } else {
  1168. bind .c <B1-Motion> { }
  1169. bind .c <ButtonRelease-1> { }
  1170. }
  1171. }
  1172. }
  1173. #########################################################################################
  1174. # Delete Unit
  1175. # correct fileHead xxxxData xxxxCounter
  1176. #########################################################################################
  1177. proc delUnit { } {
  1178. global myAppChangedFlag
  1179. global newFlag
  1180. if { $newFlag < 0 } {
  1181. promptInfo "You must setup a new palette first!"
  1182. return $newFlag
  1183. }
  1184. bind .c <Button-1> {
  1185. set curPoint [.c find withtag current]
  1186. ## puts $curPoint
  1187. if { [lsearch -exact $recId $curPoint] != -1 } {
  1188. ## puts [lsearch -exact $recId $curPoint]
  1189. ## puts [lindex $recTags [lsearch -exact $recId $curPoint]]
  1190. .c delete [lindex $recTags [lsearch -exact $recId $curPoint]]
  1191. set recData [lreplace $recData [expr {[lsearch -exact $recId $curPoint]*8] \
  1192. [expr {[lsearch -exact $recId $curPoint]*8+7 }]]
  1193. set fileHead [lreplace $fileHead 1 1 [expr {[lindex $fileHead 1]-1 }]]
  1194. ## puts $fileHead
  1195. if {[lsearch -exact $recId $curPoint] < [lindex $fileHead 1]} {
  1196. for {set counter [lsearch -exact $recId $curPoint]} \
  1197. {$counter<[lindex $fileHead 1]} {incr counter} {
  1198. set olddata [expr {$counter*8+3 }]
  1199. ## puts $olddata
  1200. set recData [lreplace $recData $olddata $olddata \
  1201. [expr {[lindex $recData $olddata]-1 }]]
  1202. set tempdata [lindex $recData $olddata]
  1203. set recData [lreplace $recData [expr {$olddata-1 }] [expr {$olddata-1 }] \
  1204. recTags$tempdata]
  1205. ## puts $recData
  1206. ## puts recTags[expr {$counter+2 }]
  1207. .c addtag recTags[expr {$counter+1 }] withtag recTags[expr {$counter+2 }]
  1208. .c dtag recTags[expr {$counter+2 }]
  1209. }
  1210. }
  1211. set recCounter [expr {$recCounter-1 }]
  1212. ## puts $recCounter
  1213. set recTags [lreplace $recTags $recCounter $recCounter]
  1214. #delete the last element.
  1215. set recId [lreplace $recId [lsearch -exact $recId $curPoint] \
  1216. [lsearch -exact $recId $curPoint]]
  1217. ## puts $recTags
  1218. ## puts $recId
  1219. set myAppChangedFlag 1
  1220. } elseif { [lsearch -exact $cirId $curPoint] != -1 } {
  1221. ## puts [lsearch -exact $cirId $curPoint]
  1222. ## puts [lindex $cirTags [lsearch -exact $cirId $curPoint]]
  1223. .c delete [lindex $cirTags [lsearch -exact $cirId $curPoint]]
  1224. set cirData [lreplace $cirData [expr {[lsearch -exact $cirId $curPoint]*7] \
  1225. [expr {[lsearch -exact $cirId $curPoint]*7+6 }]]
  1226. set fileHead [lreplace $fileHead 2 2 [expr {[lindex $fileHead 2]-1 }]]
  1227. ## puts $fileHead
  1228. if {[lsearch -exact $cirId $curPoint] < [lindex $fileHead 2]} {
  1229. for {set counter [lsearch -exact $cirId $curPoint]} \
  1230. {$counter<[lindex $fileHead 2]} {incr counter} {
  1231. set olddata [expr {$counter*7+3 }]
  1232. ## puts $olddata
  1233. set cirData [lreplace $cirData $olddata $olddata \
  1234. [expr {[lindex $cirData $olddata]-1 }]]
  1235. set tempdata [lindex $cirData $olddata]
  1236. set cirData [lreplace $cirData [expr {$olddata-1 }] [expr {$olddata-1 }] \
  1237. cirTags$tempdata]
  1238. ## puts $cirData
  1239. ## puts cirTags[expr {$counter+2 }]
  1240. .c addtag cirTags[expr {$counter+1 }] withtag cirTags[expr {$counter+2 }]
  1241. .c dtag cirTags[expr {$counter+2 }]
  1242. }
  1243. }
  1244. set cirCounter [expr {$cirCounter-1 }]
  1245. ## puts $cirCounter
  1246. set cirTags [lreplace $cirTags $cirCounter $cirCounter]
  1247. #delete the last element.
  1248. set cirId [lreplace $cirId [lsearch -exact $cirId $curPoint] \
  1249. [lsearch -exact $cirId $curPoint]]
  1250. ## puts $cirTags
  1251. ## puts $cirId
  1252. set myAppChangedFlag 1
  1253. } elseif { [lsearch -exact $dieleId $curPoint] != -1 } {
  1254. ## puts [lsearch -exact $dieleId $curPoint]
  1255. ## puts [lindex $dieleTags [lsearch -exact $dieleId $curPoint]]
  1256. .c delete [lindex $dieleTags [lsearch -exact $dieleId $curPoint]]
  1257. set dieleData [lreplace $dieleData [expr {[lsearch -exact $dieleId $curPoint]*9 }] \
  1258. [expr {[lsearch -exact $dieleId $curPoint]*9+8 }]]
  1259. set fileHead [lreplace $fileHead 0 0 [expr {[lindex $fileHead 0]-1 }]]
  1260. ## puts $fileHead
  1261. if {[lsearch -exact $dieleId $curPoint] < [lindex $fileHead 0]} {
  1262. for {set counter [lsearch -exact $dieleId $curPoint]} \
  1263. {$counter<[lindex $fileHead 0]} {incr counter} {
  1264. set olddata [expr {$counter*9+3 }]
  1265. ## puts $olddata
  1266. set dieleData [lreplace $dieleData $olddata $olddata \
  1267. [expr {[lindex $dieleData $olddata]-1 }]]
  1268. set tempdata [lindex $dieleData $olddata }]
  1269. set dieleData [lreplace $dieleData [expr {$olddata-1 }] [expr {$olddata-1 }] \
  1270. dieleTags$tempdata]
  1271. ## puts $dieleData
  1272. ## puts dieleTags[expr {$counter+2 }]
  1273. .c addtag dieleTags[expr {$counter+1 }] withtag dieleTags[expr {$counter+2 }]
  1274. .c dtag dieleTags[expr {$counter+2 }]
  1275. }
  1276. }
  1277. set dieleCounter [expr {$dieleCounter-1 }]
  1278. ## puts $dieleCounter
  1279. set dieleTags [lreplace $dieleTags $dieleCounter $dieleCounter]
  1280. set dieleId [lreplace $dieleId [lsearch -exact $dieleId $curPoint] \
  1281. [lsearch -exact $dieleId $curPoint]]
  1282. ## puts $dieleTags
  1283. ## puts $dieleId
  1284. set myAppChangedFlag 1
  1285. } elseif { [lsearch -exact $ellId $curPoint] != -1 } {
  1286. ## puts [lsearch -exact $ellId $curPoint]
  1287. ## puts [lindex $ellTags [lsearch -exact $ellId $curPoint]]
  1288. .c delete [lindex $ellTags [lsearch -exact $ellId $curPoint]]
  1289. set ellData [lreplace $ellData [expr {[lsearch -exact $ellId $curPoint]*8 }] \
  1290. [expr {[lsearch -exact $ellId $curPoint]*8+7 }]]
  1291. set fileHead [lreplace $fileHead 4 4 [expr {[lindex $fileHead 4]-1 }]]
  1292. ## puts $fileHead
  1293. if {[lsearch -exact $ellId $curPoint] < [lindex $fileHead 4]} {
  1294. for {set counter [lsearch -exact $ellId $curPoint]} \
  1295. {$counter<[lindex $fileHead 4]} {incr counter} {
  1296. set olddata [expr {$counter*8+3 }]
  1297. ## puts $olddata
  1298. set ellData [lreplace $ellData $olddata $olddata \
  1299. [expr {[lindex $ellData $olddata]-1 }]]
  1300. set tempdata [lindex $ellData $olddata]
  1301. set ellData [lreplace $ellData [expr {$olddata-1 }] [expr {$olddata-1 }] \
  1302. ellTags$tempdata]
  1303. ## puts $ellData
  1304. ## puts ellTags[expr {$counter+2 }]
  1305. .c addtag ellTags[expr {$counter+1 }] withtag ellTags[expr {$counter+2 }]
  1306. .c dtag ellTags[expr {$counter+2 }]
  1307. }
  1308. }
  1309. set ellCounter [expr {$ellCounter-1 }]
  1310. ## puts $ellCounter
  1311. set ellTags [lreplace $ellTags $ellCounter $ellCounter]
  1312. set ellId [lreplace $ellId [lsearch -exact $ellId $curPoint] \
  1313. [lsearch -exact $ellId $curPoint]]
  1314. ## puts $ellTagsq
  1315. ## puts $ellId
  1316. set myAppChangedFlag 1
  1317. } elseif { [lsearch -exact $triId $curPoint] != -1 } {
  1318. ## puts [lsearch -exact $triId $curPoint]
  1319. ## puts [lindex $triTags [lsearch -exact $triId $curPoint] }]
  1320. .c delete [lindex $triTags [lsearch -exact $triId $curPoint]]
  1321. set triData [lreplace $triData [expr {[lsearch -exact $triId $curPoint]*10 }] \
  1322. [expr {[lsearch -exact $triId $curPoint]*10+9 }]]
  1323. set fileHead [lreplace $fileHead 3 3 [expr {[lindex $fileHead 3]-1 }]]
  1324. ## puts $fileHead
  1325. if {[lsearch -exact $triId $curPoint] < [lindex $fileHead 3]} {
  1326. for {set counter [lsearch -exact $triId $curPoint]} \
  1327. {$counter<[lindex $fileHead 3]} {incr counter} {
  1328. set olddata [expr {$counter*10+3 }]
  1329. ## puts $olddata
  1330. set triData [lreplace $triData $olddata $olddata \
  1331. [expr {[lindex $triData $olddata]-1 }]]
  1332. set tempdata [lindex $triData $olddata]
  1333. set triData [lreplace $triData [expr {$olddata-1 }] [expr {$olddata-1 }] \
  1334. triTags$tempdata]
  1335. ## puts $triData
  1336. ## puts triTags[expr {$counter+2 }]
  1337. .c addtag triTags[expr {$counter+1 }] withtag triTags[expr {$counter+2 }]
  1338. .c dtag triTags[expr {$counter+2 }]
  1339. }
  1340. }
  1341. set triCounter [expr {$triCounter-1 }]
  1342. ## puts $triCounter
  1343. set triTags [lreplace $triTags $triCounter $triCounter]
  1344. set triId [lreplace $triId [lsearch -exact $triId $curPoint] \
  1345. [lsearch -exact $triId $curPoint]]
  1346. ## puts $triTags
  1347. ## puts $triId
  1348. set myAppChangedFlag 1
  1349. } elseif { [lsearch -exact $polyId $curPoint] != -1 } {
  1350. ## puts [lsearch -exact $polyId $curPoint]
  1351. ## puts [lindex $polyTags [lsearch -exact $polyId $curPoint]]
  1352. .c delete [lindex $polyTags [lsearch -exact $polyId $curPoint]]
  1353. setTag $curPoint $polyId $polyTags $polyData
  1354. set idSite $curPosition
  1355. set curPosition1 $curPosition
  1356. ## puts $idSite
  1357. ## puts [expr {$idSite+2+[lindex $polyData [expr {$idSite+2 }]]*2 }]
  1358. set polyData [lreplace $polyData [expr {$idSite-2 }] [expr {$idSite+2+ \
  1359. [lindex $polyData [expr {$idSite+2 }]]*2 }]]
  1360. ## puts $polyData
  1361. set fileHead [lreplace $fileHead 5 5 [expr {[lindex $fileHead 5]-1 }]]
  1362. ## puts $fileHead
  1363. if {[lsearch -exact $polyId $curPoint] < [lindex $fileHead 5]} {
  1364. for {set counter [lsearch -exact $polyId $curPoint]} \
  1365. {$counter<[lindex $fileHead 5]} {incr counter} {
  1366. set olddata [expr {$curPosition1+1 }]
  1367. set polyData [lreplace $polyData $olddata $olddata \
  1368. [expr {[lindex $polyData $olddata]-1 }]]
  1369. set tempdata [lindex $polyData $olddata]
  1370. set polyData [lreplace $polyData [expr {$olddata-1 }] [expr {$olddata-1 }] \
  1371. polyTags$tempdata]
  1372. .c addtag polyTags[expr {$counter+1 }] withtag polyTags[expr {$counter+2 }]
  1373. .c dtag polyTags[expr {$counter+2 }]
  1374. set curPosition1 [expr {$curPosition1+5+[lindex $polyData \
  1375. [expr {$curPosition1+2}]]*2}]
  1376. }
  1377. }
  1378. set polyCounter [expr {$polyCounter-1 }]
  1379. ## puts $polyCounter
  1380. set polyTags [lreplace $polyTags $polyCounter $polyCounter]
  1381. set polyId [lreplace $polyId [lsearch -exact $polyId $curPoint] \
  1382. [lsearch -exact $polyId $curPoint]]
  1383. ## puts $polyData
  1384. ## puts $polyTags
  1385. ## puts $polyId
  1386. set myAppChangedFlag 1
  1387. } elseif { [lsearch -exact $gndId $curPoint] != -1 } {
  1388. ## puts [lsearch -exact $gndId $curPoint]
  1389. ## puts [lindex $gndTags [lsearch -exact $gndId $curPoint]]
  1390. .c delete [lindex $gndTags [lsearch -exact $gndId $curPoint]]
  1391. set gndData [lreplace $gndData [expr {[lsearch -exact $gndId $curPoint]*8 }] \
  1392. [expr {[lsearch -exact $gndId $curPoint]*8+7 }]]
  1393. set fileHead [lreplace $fileHead 6 6 [expr {[lindex $fileHead 6]-1 }]]
  1394. ## puts $fileHead
  1395. if {[lsearch -exact $gndId $curPoint] < [lindex $fileHead 6]} {
  1396. for {set counter [lsearch -exact $gndId $curPoint]} \
  1397. {$counter<[lindex $fileHead 6]} {incr counter} {
  1398. set olddata [expr {$counter*8+3 }]
  1399. ## puts $olddata
  1400. set gndData [lreplace $gndData $olddata $olddata \
  1401. [expr {[lindex $gndData $olddata]-1 }]]
  1402. set tempdata [lindex $gndData $olddata]
  1403. set gndData [lreplace $gndData [expr {$olddata-1 }] [expr {$olddata-1 }] \
  1404. gndTags$tempdata]
  1405. ## puts $gndData
  1406. ## puts gndTags[expr {$counter+2 }]
  1407. .c addtag gndTags[expr {$counter+1 }] withtag gndTags[expr {$counter+2 }]
  1408. .c dtag gndTags[expr {$counter+2 }]
  1409. }
  1410. }
  1411. set gndCounter [expr {$gndCounter-1 }]
  1412. ## puts $gndCounter
  1413. set gndTags [lreplace $gndTags $gndCounter $gndCounter]
  1414. set gndId [lreplace $gndId [lsearch -exact $gndId $curPoint] \
  1415. [lsearch -exact $gndId $curPoint]]
  1416. ## puts $gndTags
  1417. ## puts $gndId
  1418. set myAppChangedFlag 1
  1419. }
  1420. }
  1421. }
  1422. ################################################################################################
  1423. # hand create graphs
  1424. ################################################################################################
  1425. proc dispRect { w title startpoint } {
  1426. global palFlag corFlag newFlag
  1427. global recData
  1428. global rectx recty rectwidth rectheight rectcond
  1429. global startpoint1
  1430. checkPal
  1431. if { $palFlag < 0 } {
  1432. return $palFlag
  1433. }
  1434. if { $newFlag < 0 } {
  1435. promptInfo "You must setup a new palette first!"
  1436. return $newFlag
  1437. }
  1438. toplevel $w -class Dialog
  1439. wm title $w $title
  1440. wm iconname $w Dialog
  1441. frame $w.top -relief raised -bd 1
  1442. pack $w.top -side top -fill both
  1443. frame $w.bot -relief raised -bd 1
  1444. pack $w.bot -side bottom -fill both
  1445. if { $corFlag == 0 } {
  1446. set rectx [lindex $recData [expr {$startpoint+2 }]]
  1447. set recty [lindex $recData [expr {$startpoint+3 }]]
  1448. set rectwidth [lindex $recData [expr {$startpoint+4 }]]
  1449. set rectheight [lindex $recData [expr {$startpoint+5 }]]
  1450. }
  1451. grid [label $w.top.lab1 -text "LowerLeft X Coord"] \
  1452. [entry $w.top.ent1 -textvariable rectx] -sticky e
  1453. grid [label $w.top.lab2 -text "LowerLeft Y Coord"] \
  1454. [entry $w.top.ent2 -textvariable recty] -sticky e
  1455. grid [label $w.top.lab3 -text "Width"] \
  1456. [entry $w.top.ent3 -textvariable rectwidth] -sticky e
  1457. grid [label $w.top.lab4 -text "Height"] \
  1458. [entry $w.top.ent4 -textvariable rectheight] -sticky e
  1459. set startpoint1 $startpoint
  1460. button $w.bot.buttonok -text "OK" -command {
  1461. if { $corFlag == -1 } {
  1462. rectOk $rectx $recty $rectwidth $rectheight {}
  1463. destroy .rectPara
  1464. } else {
  1465. rectOk $rectx $recty $rectwidth $rectheight $startpoint1
  1466. destroy .rectPara
  1467. }
  1468. }
  1469. button $w.bot.buttoncancel -text "CANCEL" -command { destroy .rectPara }
  1470. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  1471. }
  1472. proc rectOk { rectx recty rectw recth startpoint } {
  1473. global myAppChangedFlag
  1474. global recCounter recId recTags
  1475. global Xscale Yscale
  1476. global maxYcoord
  1477. global pbottomleftX pbottomleftY
  1478. global fileHead recData
  1479. global corFlag
  1480. ## puts "corFlag"
  1481. ## puts $corFlag
  1482. if { $corFlag ==0 } {
  1483. ## puts [lindex $recData [expr {$startpoint }]]
  1484. .c coords [lindex $recData [expr {$startpoint }]] \
  1485. [expr {($rectx-$pbottomleftX)*$Xscale }] \
  1486. [expr {$maxYcoord-($recty-$pbottomleftY)*$Yscale }] \
  1487. [expr {($rectx+$rectw-$pbottomleftX)*$Xscale }] \
  1488. [expr {$maxYcoord-($recty+$recth-$pbottomleftY)*$Yscale }]
  1489. set recData [lreplace $recData [expr {$startpoint+2 }] [expr {$startpoint+2 }] \
  1490. $rectx]
  1491. set recData [lreplace $recData [expr {$startpoint+3 }] [expr {$startpoint+3 }] \
  1492. $recty]
  1493. set recData [lreplace $recData [expr {$startpoint+4 }] [expr {$startpoint+4 }] \
  1494. $rectw]
  1495. set recData [lreplace $recData [expr {$startpoint+5 }] [expr {$startpoint+5 }] \
  1496. $recth]
  1497. ## puts $recData
  1498. } else {
  1499. incr recCounter
  1500. ## puts [expr {$rectx*$Xscale }]
  1501. ## puts [expr {($maxYcoord-$recty)*$Yscale }]
  1502. ## puts [expr {($rectx+$rectw)*$Xscale }]
  1503. ## puts [expr {$maxYcoord-($recty-$recth)*$Yscale }]
  1504. set rect [.c create rectangle [expr {($rectx-$pbottomleftX)*$Xscale }] \
  1505. [expr {$maxYcoord-($recty-$pbottomleftY)*$Yscale }] \
  1506. [expr {($rectx+$rectw-$pbottomleftX)*$Xscale }] \
  1507. [expr {$maxYcoord-($recty+$recth-$pbottomleftY)*$Yscale }] \
  1508. -outline white -fill yellow -tags recTags$recCounter]
  1509. lappend recId $rect
  1510. lappend recTags recTags$recCounter
  1511. ## puts $recCounter
  1512. ## puts $recId
  1513. ## puts $recTags
  1514. set fileHead [lreplace $fileHead 1 1 [expr {[lindex $fileHead 1]+1 }]]
  1515. ## puts $fileHead
  1516. lappend recData "REC"
  1517. lappend recData $rect
  1518. lappend recData recTags$recCounter
  1519. lappend recData $recCounter
  1520. lappend recData $rectx
  1521. lappend recData $recty
  1522. lappend recData $rectw
  1523. lappend recData $recth
  1524. ## puts $recData
  1525. set myAppChangedFlag 1
  1526. }
  1527. }
  1528. proc dispCir { w title startpoint } {
  1529. global palFlag corFlag newFlag
  1530. global cirData
  1531. global circenterX circenterY cirRadius cirCond
  1532. global startpoint1
  1533. checkPal
  1534. if { $palFlag < 0 } {
  1535. return $palFlag
  1536. }
  1537. if { $newFlag < 0 } {
  1538. promptInfo "You must setup a new palette first!"
  1539. return $newFlag
  1540. }
  1541. toplevel $w -class Dialog
  1542. wm title $w $title
  1543. wm iconname $w Dialog
  1544. frame $w.top -relief raised -bd 1
  1545. pack $w.top -side top -fill both
  1546. frame $w.bot -relief raised -bd 1
  1547. pack $w.bot -side bottom -fill both
  1548. grid [label $w.top.lab1 -text "Center X Coord"] \
  1549. [entry $w.top.ent1 -textvariable circenterX] -sticky e
  1550. grid [label $w.top.lab2 -text "Center Y Coord"] \
  1551. [entry $w.top.ent2 -textvariable circenterY] -sticky e
  1552. grid [label $w.top.lab3 -text "radius"] \
  1553. [entry $w.top.ent3 -textvariable cirRadius] -sticky e
  1554. if { $corFlag == 0 } {
  1555. set circenterX [lindex $cirData [expr {$startpoint+2 }]]
  1556. set circenterY [lindex $cirData [expr {$startpoint+3 }]]
  1557. set cirRadius [lindex $cirData [expr {$startpoint+4 }]]
  1558. }
  1559. set startpoint1 $startpoint
  1560. button $w.bot.buttonok -text "OK" -command {
  1561. if { $corFlag == -1 } {
  1562. cirOk $circenterX $circenterY $cirRadius {}
  1563. destroy .cirPara
  1564. } else {
  1565. cirOk $circenterX $circenterY $cirRadius $startpoint1
  1566. destroy .cirPara
  1567. }
  1568. }
  1569. button $w.bot.buttoncancel -text "CANCEL" -command { destroy .cirPara }
  1570. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  1571. }
  1572. proc cirOk { cirx ciry cirr startpoint } {
  1573. global myAppChangedFlag
  1574. global cirCounter cirId cirTags
  1575. global Xscale Yscale
  1576. global maxYcoord
  1577. global pbottomleftX pbottomleftY
  1578. global fileHead cirData
  1579. global corFlag
  1580. if { $corFlag ==0 } {
  1581. ## puts [lindex $cirData [expr {$startpoint }]]
  1582. .c coords [lindex $cirData [expr {$startpoint }]] \
  1583. [expr {($cirx-$cirr-$pbottomleftX)*$Xscale }] \
  1584. [expr {$maxYcoord-($ciry-$cirr-$pbottomleftY)*$Yscale }] \
  1585. [expr {($cirx+$cirr-$pbottomleftX)*$Xscale }] \
  1586. [expr {$maxYcoord-($ciry+$cirr-$pbottomleftY)*$Yscale }]
  1587. set cirData [lreplace $cirData [expr {$startpoint+2 }] [expr {$startpoint+2 }] \
  1588. $cirx]
  1589. set cirData [lreplace $cirData [expr {$startpoint+3 }] [expr {$startpoint+3 }] \
  1590. $ciry]
  1591. set cirData [lreplace $cirData [expr {$startpoint+4 }] [expr {$startpoint+4 }] \
  1592. $cirr]
  1593. ## puts $cirData
  1594. } else {
  1595. incr cirCounter
  1596. set cir [.c create oval [expr {($cirx-$cirr-$pbottomleftX)*$Xscale }] [expr {\
  1597. $maxYcoord-($ciry-$cirr-$pbottomleftY)*$Yscale }] \
  1598. [expr {($cirx+$cirr-$pbottomleftX)*$Xscale }] \
  1599. [expr {$maxYcoord-($ciry+$cirr-$pbottomleftY)*$Yscale }] \
  1600. -outline white -fill red -tags cirTags$cirCounter]
  1601. lappend cirId $cir
  1602. lappend cirTags cirTags$cirCounter
  1603. set fileHead [lreplace $fileHead 2 2 [expr {[lindex $fileHead 2]+1 }]]
  1604. ## puts $fileHead
  1605. lappend cirData "CIR"
  1606. lappend cirData $cir
  1607. lappend cirData cirTags$cirCounter
  1608. lappend cirData $cirCounter
  1609. lappend cirData $cirx
  1610. lappend cirData $ciry
  1611. lappend cirData $cirr
  1612. ## puts $cirData
  1613. ## puts $cirCounter
  1614. ## puts $cirId
  1615. ## puts $cirTags
  1616. set myAppChangedFlag 1
  1617. }
  1618. }
  1619. proc dispDiele { w title startpoint } {
  1620. global palFlag corFlag newFlag
  1621. global dieleData
  1622. global dieleX dieleY dieleWidth dieleHeight dielePermit dielePermea
  1623. global startpoint1
  1624. checkPal
  1625. if { $palFlag < 0 } {
  1626. return $palFlag
  1627. }
  1628. if { $newFlag < 0 } {
  1629. promptInfo "You must setup a new palette first!"
  1630. return $newFlag
  1631. }
  1632. toplevel $w -class Dialog
  1633. wm title $w $title
  1634. wm iconname $w Dialog
  1635. frame $w.top -relief raised -bd 1
  1636. pack $w.top -side top -fill both
  1637. frame $w.bot -relief raised -bd 1
  1638. pack $w.bot -side bottom -fill both
  1639. grid [label $w.top.lab1 -text "BottomLeft X Coord"] \
  1640. [entry $w.top.ent1 -textvariable dieleX] -sticky e
  1641. grid [label $w.top.lab2 -text "BottomLeft Y Coord"] \
  1642. [entry $w.top.ent2 -textvariable dieleY] -sticky e
  1643. grid [label $w.top.lab3 -text "Width"] \
  1644. [entry $w.top.ent3 -textvariable dieleWidth] -sticky e
  1645. grid [label $w.top.lab4 -text "Height"] \
  1646. [entry $w.top.ent4 -textvariable dieleHeight] -sticky e
  1647. grid [label $w.top.lab5 -text "Relative Permitivity"] \
  1648. [entry $w.top.ent5 -textvariable dielePermit] -sticky e
  1649. if { $corFlag == 0 } {
  1650. set dieleX [lindex $dieleData [expr {$startpoint+2 }]]
  1651. set dieleY [lindex $dieleData [expr {$startpoint+3 }]]
  1652. set dieleWidth [lindex $dieleData [expr {$startpoint+4 }]]
  1653. set dieleHeight [lindex $dieleData [expr {$startpoint+5 }]]
  1654. set dielePermit [lindex $dieleData [expr {$startpoint+6 }]]
  1655. ## puts $dieleData
  1656. }
  1657. set startpoint1 $startpoint
  1658. button $w.bot.buttonok -text "OK" -command {
  1659. if { $corFlag == -1 } {
  1660. dieleOk $dieleX $dieleY $dieleWidth $dieleHeight $dielePermit {}
  1661. destroy .dielePara
  1662. } else {
  1663. dieleOk $dieleX $dieleY $dieleWidth $dieleHeight $dielePermit \
  1664. $startpoint1
  1665. destroy .dielePara
  1666. }
  1667. }
  1668. button $w.bot.buttoncancel -text "CANCEL" -command { destroy .dielePara }
  1669. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  1670. }
  1671. proc dieleOk { dielex dieley dielew dieleh dielepermit startpoint } {
  1672. global dieleCounter dieleId dieleTags
  1673. global Xscale Yscale
  1674. global maxYcoord
  1675. global dieleData fileHead
  1676. global pbottomleftX pbottomleftY
  1677. global corFlag
  1678. global myAppChangedFlag
  1679. global maxga
  1680. if { $corFlag ==0 } {
  1681. ## puts [lindex $dieleData [expr {$startpoint }]]
  1682. .c coords [lindex $dieleData [expr {$startpoint }]] \
  1683. [expr {($dielex-$pbottomleftX)*$Xscale }] \
  1684. [expr {$maxYcoord-($dieley-$pbottomleftY)*$Yscale }] \
  1685. [expr {($dielex+$dielew-$pbottomleftX)*$Xscale }] \
  1686. [expr {$maxYcoord-($dieley+$dieleh-$pbottomleftY)*$Yscale }]
  1687. set dieleData [lreplace $dieleData [expr {$startpoint+2 }] [expr {$startpoint+2 }] \
  1688. $dielex]
  1689. set dieleData [lreplace $dieleData [expr {$startpoint+3 }] [expr {$startpoint+3 }] \
  1690. $dieley]
  1691. set dieleData [lreplace $dieleData [expr {$startpoint+4 }] [expr {$startpoint+4 }] \
  1692. $dielew]
  1693. set dieleData [lreplace $dieleData [expr {$startpoint+5 }] [expr {$startpoint+5 }] \
  1694. $dieleh]
  1695. set dieleData [lreplace $dieleData [expr {$startpoint+6 }] [expr {$startpoint+6 }] \
  1696. $dielepermit]
  1697. ## puts $dieleData
  1698. } else {
  1699. incr dieleCounter
  1700. set diele [.c create rectangle [expr {($dielex-$pbottomleftX)*$Xscale }] \
  1701. [expr {$maxYcoord-($dieley-$pbottomleftY)*$Yscale }] \
  1702. [expr {($dielex+$dielew-$pbottomleftX)*$Xscale }] \
  1703. [expr {$maxYcoord-($dieley+$dieleh-$pbottomleftY)*$Yscale }] \
  1704. -outline white -fill black -tags dieleTags$dieleCounter]
  1705. lappend dieleId $diele
  1706. lappend dieleTags dieleTags$dieleCounter
  1707. set fileHead [lreplace $fileHead 0 0 [expr {[lindex $fileHead 0]+1 }]]
  1708. ## puts $fileHead
  1709. lappend dieleData "DIELE"
  1710. lappend dieleData $diele
  1711. lappend dieleData dieleTags$dieleCounter
  1712. lappend dieleData $dieleCounter
  1713. lappend dieleData $dielex
  1714. lappend dieleData $dieley
  1715. lappend dieleData $dielew
  1716. lappend dieleData $dieleh
  1717. if { [expr {1.0/$dieleh }] > $maxga } {
  1718. set maxga [expr {1.0/$dieleh }]
  1719. }
  1720. lappend dieleData $dielepermit
  1721. set myAppChangedFlag 1
  1722. ## puts $dieleData
  1723. ## puts $dieleCounter
  1724. ## puts $dieleId
  1725. ## puts $dieleTags
  1726. }
  1727. }
  1728. proc dispEll { w title startpoint } {
  1729. global palFlag corFlag newFlag
  1730. global ellData
  1731. global ellcenterX ellcenterY ellMajor ellMinor ellCond
  1732. global startpoint1
  1733. checkPal
  1734. if { $palFlag < 0 } {
  1735. return $palFlag
  1736. }
  1737. if { $newFlag < 0 } {
  1738. promptInfo "You must setup a new palette first!"
  1739. return $newFlag
  1740. }
  1741. toplevel $w -class Dialog
  1742. wm title $w $title
  1743. wm iconname $w Dialog
  1744. frame $w.top -relief raised -bd 1
  1745. pack $w.top -side top -fill both
  1746. frame $w.bot -relief raised -bd 1
  1747. pack $w.bot -side bottom -fill both
  1748. grid [label $w.top.lab1 -text "Center X Coord"] \
  1749. [entry $w.top.ent1 -textvariable ellcenterX] -sticky e
  1750. grid [label $w.top.lab2 -text "Center Y Coord"] \
  1751. [entry $w.top.ent2 -textvariable ellcenterY] -sticky e
  1752. grid [label $w.top.lab3 -text "X Axis Length"] \
  1753. [entry $w.top.ent3 -textvariable ellMajor] -sticky e
  1754. grid [label $w.top.lab4 -text "Y Axis Length"] \
  1755. [entry $w.top.ent4 -textvariable ellMinor] -sticky e
  1756. if { $corFlag == 0 } {
  1757. set ellcenterX [lindex $ellData [expr {$startpoint+2 }]]
  1758. set ellcenterY [lindex $ellData [expr {$startpoint+3 }]]
  1759. set ellMajor [lindex $ellData [expr {$startpoint+4 }]]
  1760. set ellMinor [lindex $ellData [expr {$startpoint+5 }]]
  1761. }
  1762. set startpoint1 $startpoint
  1763. button $w.bot.buttonok -text "OK" -command {
  1764. if { $corFlag == -1 } {
  1765. ellOk $ellcenterX $ellcenterY $ellMajor $ellMinor {}
  1766. destroy .ellPara
  1767. } else {
  1768. ellOk $ellcenterX $ellcenterY $ellMajor $ellMinor $startpoint1
  1769. destroy .ellPara
  1770. }
  1771. }
  1772. button $w.bot.buttoncancel -text "CANCEL" -command { destroy .ellPara }
  1773. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  1774. }
  1775. proc ellOk { ellx elly ellma ellmi startpoint } {
  1776. global ellCounter ellId ellTags
  1777. global Xscale Yscale
  1778. global maxYcoord
  1779. global fileHead ellData
  1780. global pbottomleftX pbottomleftY
  1781. global corFlag
  1782. global myAppChangedFlag
  1783. if { $corFlag ==0 } {
  1784. ## puts [lindex $ellData [expr {$startpoint }]]
  1785. .c coords [lindex $ellData [expr {$startpoint }]] \
  1786. [expr {($ellx-$ellma-$pbottomleftX)*$Xscale }] \
  1787. [expr {$maxYcoord-($elly-$ellmi-$pbottomleftY)*$Yscale }] \
  1788. [expr {($ellx+$ellma-$pbottomleftX)*$Xscale }] \
  1789. [expr {$maxYcoord-($elly+$ellmi-$pbottomleftY)*$Yscale }]
  1790. set ellData [lreplace $ellData [expr {$startpoint+2 }] [expr {$startpoint+2 }] \
  1791. $ellx]
  1792. set ellData [lreplace $ellData [expr {$startpoint+3 }] [expr {$startpoint+3 }] \
  1793. $elly]
  1794. set ellData [lreplace $ellData [expr {$startpoint+4 }] [expr {$startpoint+4 }] \
  1795. $ellma]
  1796. set ellData [lreplace $ellData [expr {$startpoint+5 }] [expr {$startpoint+5 }] \
  1797. $ellmi]
  1798. ## puts $ellData
  1799. } else {
  1800. incr ellCounter
  1801. set ell [.c create oval [expr {($ellx-$ellma-$pbottomleftX)*$Xscale }] \
  1802. [expr {$maxYcoord-($elly-$ellmi-$pbottomleftY)*$Yscale }] \
  1803. [expr {($ellx+$ellma-$pbottomleftX)*$Xscale }] \
  1804. [expr {$maxYcoord-($elly+$ellmi-$pbottomleftY)*$Yscale }] \
  1805. -outline black -fill white -tags ellTags$ellCounter]
  1806. lappend ellId $ell
  1807. lappend ellTags ellTags$ellCounter
  1808. set fileHead [lreplace $fileHead 4 4 [expr {[lindex $fileHead 4]+1 }]]
  1809. ## puts $fileHead
  1810. lappend ellData "ELL"
  1811. lappend ellData $ell
  1812. lappend ellData ellTags$ellCounter
  1813. lappend ellData $ellCounter
  1814. lappend ellData $ellx
  1815. lappend ellData $elly
  1816. lappend ellData $ellma
  1817. lappend ellData $ellmi
  1818. set myAppChangedFlag 1
  1819. ## puts $ellData
  1820. ## puts $ellCounter
  1821. ## puts $ellId
  1822. ## puts $ellTags
  1823. }
  1824. }
  1825. proc dispTri { w title startpoint } {
  1826. global palFlag corFlag newFlag
  1827. global triData
  1828. global triapex1X triapex1Y triapex2X triapex2Y triapex3X triapex3Y triCond
  1829. global startpoint1
  1830. checkPal
  1831. if { $palFlag < 0 } {
  1832. return $palFlag
  1833. }
  1834. if { $newFlag < 0 } {
  1835. promptInfo "You must setup a new palette first!"
  1836. return $newFlag
  1837. }
  1838. toplevel $w -class Dialog
  1839. wm title $w $title
  1840. wm iconname $w Dialog
  1841. frame $w.top -relief raised -bd 1
  1842. pack $w.top -side top -fill both
  1843. frame $w.bot -relief raised -bd 1
  1844. pack $w.bot -side bottom -fill both
  1845. grid [label $w.top.lab1 -text "Apex 1 X Coord"] \
  1846. [entry $w.top.ent1 -textvariable triapex1X] -sticky e
  1847. grid [label $w.top.lab2 -text "Apex 1 Y Coord"] \
  1848. [entry $w.top.ent2 -textvariable triapex1Y] -sticky e
  1849. grid [label $w.top.lab3 -text "Apex 2 X Coord"] \
  1850. [entry $w.top.ent3 -textvariable triapex2X] -sticky e
  1851. grid [label $w.top.lab4 -text "Apex 2 Y Coord"] \
  1852. [entry $w.top.ent4 -textvariable triapex2Y] -sticky e
  1853. grid [label $w.top.lab5 -text "Apex 3 X Coord"] \
  1854. [entry $w.top.ent5 -textvariable triapex3X] -sticky e
  1855. grid [label $w.top.lab6 -text "Apex 3 Y Coord"] \
  1856. [entry $w.top.ent6 -textvariable triapex3Y] -sticky e
  1857. if { $corFlag == 0 } {
  1858. set triapex1X [lindex $triData [expr {$startpoint+2 }]]
  1859. set triapex1Y [lindex $triData [expr {$startpoint+3 }]]
  1860. set triapex2X [lindex $triData [expr {$startpoint+4 }]]
  1861. set triapex2Y [lindex $triData [expr {$startpoint+5 }]]
  1862. set triapex3X [lindex $triData [expr {$startpoint+6 }]]
  1863. set triapex3Y [lindex $triData [expr {$startpoint+7 }]]
  1864. }
  1865. set startpoint1 $startpoint
  1866. button $w.bot.buttonok -text "OK" -command {
  1867. if { $corFlag == -1 } {
  1868. triOk $triapex1X $triapex1Y $triapex2X $triapex2Y $triapex3X $triapex3Y {}
  1869. destroy .triPara
  1870. } else {
  1871. triOk $triapex1X $triapex1Y $triapex2X $triapex2Y $triapex3X $triapex3Y $startpoint1
  1872. destroy .triPara
  1873. }
  1874. }
  1875. button $w.bot.buttoncancel -text "CANCEL" -command { destroy .triPara }
  1876. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  1877. }
  1878. proc triOk { tri1x tri1y tri2x tri2y tri3x tri3y startpoint } {
  1879. global triCounter triId triTags
  1880. global Xscale Yscale
  1881. global maxYcoord
  1882. global fileHead triData
  1883. global pbottomleftX pbottomleftY
  1884. global corFlag
  1885. global myAppChangedFlag
  1886. if { $corFlag ==0 } {
  1887. ## puts [lindex $triData [expr {$startpoint }]]
  1888. .c coords [lindex $triData [expr {$startpoint }]] \
  1889. [expr {($tri1x-$pbottomleftX)*$Xscale }] \
  1890. [expr {$maxYcoord-($tri1y-$pbottomleftY)*$Yscale }] \
  1891. [expr {($tri2x-$pbottomleftX)*$Xscale }] \
  1892. [expr {$maxYcoord-($tri2y-$pbottomleftY)*$Yscale }] \
  1893. [expr {($tri3x-$pbottomleftX)*$Xscale }] \
  1894. [expr {$maxYcoord-($tri3y-$pbottomleftY)*$Yscale }]
  1895. set triData [lreplace $triData [expr {$startpoint+2 }] [expr {$startpoint+2 }] \
  1896. $tri1x]
  1897. set triData [lreplace $triData [expr {$startpoint+3 }] [expr {$startpoint+3 }] \
  1898. $tri1y]
  1899. set triData [lreplace $triData [expr {$startpoint+4 }] [expr {$startpoint+4 }] \
  1900. $tri2x]
  1901. set triData [lreplace $triData [expr {$startpoint+5 }] [expr {$startpoint+5 }] \
  1902. $tri2y]
  1903. set triData [lreplace $triData [expr {$startpoint+6 }] [expr {$startpoint+6 }] \
  1904. $tri3x]
  1905. set triData [lreplace $triData [expr {$startpoint+7 }] [expr {$startpoint+7 }] \
  1906. $tri3y]
  1907. ## puts $triData
  1908. } else {
  1909. incr triCounter
  1910. set tri [.c create polygon [expr {($tri1x-$pbottomleftX)*$Xscale }] \
  1911. [expr {$maxYcoord-($tri1y-$pbottomleftY)*$Yscale }] \
  1912. [expr {($tri2x-$pbottomleftX)*$Xscale }] \
  1913. [expr {$maxYcoord-($tri2y-$pbottomleftY)*$Yscale }] \
  1914. [expr {($tri3x-$pbottomleftX)*$Xscale }] \
  1915. [expr {$maxYcoord-($tri3y-$pbottomleftY)*$Yscale }] \
  1916. -outline white -fill white -tags triTags$triCounter]
  1917. lappend triId $tri
  1918. lappend triTags triTags$triCounter
  1919. set fileHead [lreplace $fileHead 3 3 [expr {[lindex $fileHead 3]+1 }]]
  1920. ## puts $fileHead
  1921. lappend triData "TRI"
  1922. lappend triData $tri
  1923. lappend triData triTags$triCounter
  1924. lappend triData $triCounter
  1925. lappend triData $tri1x
  1926. lappend triData $tri1y
  1927. lappend triData $tri2x
  1928. lappend triData $tri2y
  1929. lappend triData $tri3x
  1930. lappend triData $tri3y
  1931. set myAppChangedFlag 1
  1932. ## puts $triData
  1933. ## puts $triCounter
  1934. ## puts $triId
  1935. ## puts $triTags
  1936. }
  1937. }
  1938. proc getApexnumdrop { } {
  1939. global apexnum
  1940. set apexnum 4
  1941. return $apexnum
  1942. }
  1943. proc getApexnum { } {
  1944. global apexnum
  1945. set apexnum1 4
  1946. dispPoly .polyPara { Polygon Conductor Parameters } $apexnum1 {}
  1947. return $apexnum1
  1948. }
  1949. proc dispPoly { w title apexnum startpoint } {
  1950. global palFlag corFlag newFlag
  1951. global pbottomleftX pbottomleftY
  1952. global startpoint1
  1953. global polyCounter polyId polyTags
  1954. global Xscale Yscale
  1955. global maxYcoord
  1956. global apexpoly
  1957. global polyData
  1958. global polyapexX1 polyapexY1 polyapexX2 polyapexY2 polyapexX3 polyapexY3
  1959. global polyapexX4 polyapexY4 polyapexX5 polyapexY5 polyapexX6 polyapexY6
  1960. global polyapexX7 polyapexY7 polyapexX8 polyapexY8 polyapexX9 polyapexY9
  1961. global polyapexX10 polyapexY10 polyapexX11 polyapexY11 polyapexX12 polyapexY12
  1962. global polyapexX13 polyapexY13 polyapexX14 polyapexY14 polyapexX15 polyapexY15
  1963. global polyapexX16 polyapexY16 polyapexX17 polyapexY17 polyapexX18 polyapexY18
  1964. global polyapexX19 polyapexY19 polyapexX20 polyapexY20
  1965. global polyCond
  1966. checkPal
  1967. if { $palFlag < 0 } {
  1968. return $palFlag
  1969. }
  1970. if { $newFlag < 0 } {
  1971. promptInfo "You must setup a new palette first!"
  1972. return $newFlag
  1973. }
  1974. set counter 1
  1975. set polyapexlist {}
  1976. set apexpoly $apexnum
  1977. toplevel $w -class Dialog
  1978. wm title $w $title
  1979. wm iconname $w Dialog
  1980. frame $w.top -relief raised -bd 1
  1981. pack $w.top -side top -fill both
  1982. frame $w.bot -relief raised -bd 1
  1983. pack $w.bot -side bottom -fill both
  1984. while { $counter <= $apexnum } {
  1985. global polyapexX polyapexY
  1986. ## puts $counter
  1987. grid [label $w.top.lab[expr {2*$counter }] -text "Apex$counter X Coord"] \
  1988. [entry $w.top.ent[expr {2*$counter }] -textvariable polyapexX($counter)] \
  1989. -sticky e
  1990. grid [label $w.top.lab[expr {2*$counter+1 }] -text "Apex$counter Y Coord"] \
  1991. [entry $w.top.ent[expr {2*$counter+1 }] -textvariable polyapexY($counter)] -sticky e
  1992. incr counter
  1993. }
  1994. if { $corFlag == 0 } {
  1995. for {set counter 1} {$counter<=$apexnum} {incr counter} {
  1996. set polyapexX($counter) [lindex $polyData [expr {$startpoint+2*$counter+1 }]]
  1997. set polyapexY($counter) [lindex $polyData [expr {$startpoint+2*$counter+2 }]]
  1998. }
  1999. }
  2000. set startpoint1 $startpoint
  2001. button $w.bot.buttonok -text "OK" -command {
  2002. set polyapexlist [expr {($polyapexX(1)-$pbottomleftX)*$Xscale }]
  2003. lappend polyapexlist [expr {$maxYcoord-($polyapexY(1)-$pbottomleftY)*$Yscale }]
  2004. for {set counter 2} {$counter<=$apexpoly} {incr counter} {
  2005. lappend polyapexlist [expr {($polyapexX($counter)-$pbottomleftX)*$Xscale }]
  2006. lappend polyapexlist [expr {$maxYcoord-($polyapexY($counter)-$pbottomleftY)*$Yscale }]
  2007. }
  2008. ## puts $polyapexlist
  2009. if { $corFlag == -1 } {
  2010. polyOk $polyapexlist {}
  2011. } else {
  2012. polyOk $polyapexlist $startpoint1
  2013. }
  2014. destroy .polyPara
  2015. }
  2016. button $w.bot.buttoncancel -text "CANCEL" -command { destroy .polyPara }
  2017. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  2018. }
  2019. proc polyOk { polyapexlist startpoint } {
  2020. global polyCounter polyId polyTags
  2021. global Xscale Yscale
  2022. global fileHead polyData
  2023. global paletteYsize
  2024. global pbottomleftX pbottomleftY
  2025. global maxYcoord
  2026. global corFlag
  2027. global myAppChangedFlag
  2028. if { $corFlag ==0 } {
  2029. ## puts [lindex $polyData [expr {$startpoint }]]
  2030. .c coords [lindex $polyData [expr {$startpoint }]] $polyapexlist
  2031. for {set i 0} {$i < [expr {[llength $polyapexlist]/2 }]} {incr i} {
  2032. set polyData [lreplace $polyData [expr {$startpoint+3+2*$i }] \
  2033. [expr {$startpoint+3+2*$i }] \
  2034. [expr {[lindex $polyapexlist [expr {2*$i }]]/$Xscale+$pbottomleftX }]]
  2035. set polyData [lreplace $polyData [expr {$startpoint+4+2*$i }] \
  2036. [expr {$startpoint+4+2*$i }] \
  2037. [expr {($maxYcoord-[lindex $polyapexlist \
  2038. [expr {2*$i+1 }]])/$Yscale+$pbottomleftY }]]
  2039. }
  2040. ## puts $polyData
  2041. } else {
  2042. incr polyCounter
  2043. set poly [.c create polygon $polyapexlist \
  2044. -outline white -fill blue -tags polyTags$polyCounter]
  2045. lappend polyId $poly
  2046. lappend polyTags polyTags$polyCounter
  2047. set fileHead [lreplace $fileHead 5 5 [expr {[lindex $fileHead 5]+1 }]]
  2048. ## puts $fileHead
  2049. lappend polyData "POLY"
  2050. lappend polyData $poly
  2051. lappend polyData polyTags$polyCounter
  2052. lappend polyData $polyCounter
  2053. lappend polyData [expr {[llength $polyapexlist]/2 }]
  2054. ## puts [llength $polyapexlist]
  2055. for {set i 0} {$i < [expr {[llength $polyapexlist]/2 }]} {incr i} {
  2056. lappend polyData [expr {[lindex $polyapexlist [expr {2*$i }]]/$Xscale+$pbottomleftX }]
  2057. lappend polyData [expr {($maxYcoord-[lindex $polyapexlist \
  2058. [expr {2*$i+1 }]])/$Yscale+$pbottomleftY }]
  2059. }
  2060. set myAppChangedFlag 1
  2061. ## puts $polyData
  2062. ## puts $polyCounter
  2063. ## puts $polyId
  2064. ## puts $polyTags
  2065. }
  2066. }
  2067. proc dispGnd { w title startpoint } {
  2068. global palFlag corFlag newFlag
  2069. global gndX gndY gndWidth gndHeight gndCond
  2070. global gndData
  2071. global startpoint1
  2072. checkPal
  2073. if { $palFlag < 0 } {
  2074. return $palFlag
  2075. }
  2076. if { $newFlag < 0 } {
  2077. promptInfo "You must setup a new palette first!"
  2078. return $newFlag
  2079. }
  2080. toplevel $w -class Dialog
  2081. wm title $w $title
  2082. wm iconname $w Dialog
  2083. frame $w.top -relief raised -bd 1
  2084. pack $w.top -side top -fill both
  2085. frame $w.bot -relief raised -bd 1
  2086. pack $w.bot -side bottom -fill both
  2087. grid [label $w.top.lab1 -text "LowerLeft X Coord"] \
  2088. [entry $w.top.ent1 -textvariable gndX] -sticky e
  2089. grid [label $w.top.lab2 -text "LowerLeft Y Coord"] \
  2090. [entry $w.top.ent2 -textvariable gndY] -sticky e
  2091. grid [label $w.top.lab3 -text "Width"] \
  2092. [entry $w.top.ent3 -textvariable gndWidth] -sticky e
  2093. grid [label $w.top.lab4 -text "Height"] \
  2094. [entry $w.top.ent4 -textvariable gndHeight] -sticky e
  2095. if { $corFlag == 0 } {
  2096. set gndX [lindex $gndData [expr {$startpoint+2 }]]
  2097. set gndY [lindex $gndData [expr {$startpoint+3 }]]
  2098. set gndWidth [lindex $gndData [expr {$startpoint+4 }]]
  2099. set gndHeight [lindex $gndData [expr {$startpoint+5 }]]
  2100. }
  2101. set startpoint1 $startpoint
  2102. button $w.bot.buttonok -text "OK" -command {
  2103. if { $corFlag == -1 } {
  2104. gndOk $gndX $gndY $gndWidth $gndHeight {}
  2105. destroy .gndPara
  2106. } else {
  2107. gndOk $gndX $gndY $gndWidth $gndHeight $startpoint1
  2108. destroy .gndPara
  2109. }
  2110. }
  2111. button $w.bot.buttoncancel -text "CANCEL" -command { destroy .gndPara }
  2112. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  2113. }
  2114. proc gndOk { gndx gndy gndw gndh startpoint } {
  2115. global gndCounter gndId gndTags
  2116. global Xscale Yscale
  2117. global maxYcoord
  2118. global fileHead gndData
  2119. global pbottomleftX pbottomleftY
  2120. global corFlag
  2121. global myAppChangedFlag
  2122. if { $corFlag ==0 } {
  2123. ## puts [lindex $gndData [expr {$startpoint }]]
  2124. .c coords [lindex $gndData [expr {$startpoint }]] \
  2125. [expr {($gndx-$pbottomleftX)*$Xscale }] \
  2126. [expr {$maxYcoord-($gndy-$pbottomleftY)*$Yscale }] \
  2127. [expr {($gndx+$gndw-$pbottomleftX)*$Xscale }] \
  2128. [expr {$maxYcoord-($gndy+$gndh-$pbottomleftY)*$Yscale }]
  2129. set gndData [lreplace $gndData [expr {$startpoint+2 }] [expr {$startpoint+2 }] \
  2130. $gndx]
  2131. set gndData [lreplace $gndData [expr {$startpoint+3 }] [expr {$startpoint+3 }] \
  2132. $gndy]
  2133. set gndData [lreplace $gndData [expr {$startpoint+4 }] [expr {$startpoint+4 }] \
  2134. $gndw]
  2135. set gndData [lreplace $gndData [expr {$startpoint+5 }] [expr {$startpoint+5 }] \
  2136. $gndh]
  2137. # set gndData [lreplace $gndData [expr {$startpoint+6 }] [expr {$startpoint+6 }] \
  2138. $gndc]
  2139. ## puts $gndData
  2140. } else {
  2141. incr gndCounter
  2142. ## puts $Xscale
  2143. ## puts $Yscale
  2144. set gnd [.c create rectangle [expr {($gndx-$pbottomleftX)*$Xscale }] \
  2145. [expr {$maxYcoord-($gndy-$pbottomleftY)*$Yscale }] \
  2146. [expr {($gndx+$gndw-$pbottomleftX)*$Xscale }] \
  2147. [expr {$maxYcoord-($gndy+$gndh-$pbottomleftY)*$Yscale }] \
  2148. -outline white -fill green -tags gndTags$gndCounter]
  2149. lappend gndId $gnd
  2150. lappend gndTags gndTags$gndCounter
  2151. set fileHead [lreplace $fileHead 6 6 [expr {[lindex $fileHead 6]+1 }]]
  2152. ## puts $fileHead
  2153. lappend gndData "GND"
  2154. lappend gndData $gnd
  2155. lappend gndData gndTags$gndCounter
  2156. lappend gndData $gndCounter
  2157. lappend gndData $gndx
  2158. lappend gndData $gndy
  2159. lappend gndData $gndw
  2160. lappend gndData $gndh
  2161. # lappend gndData $gndc
  2162. set myAppChangedFlag 1
  2163. ## puts $gndData
  2164. ## puts $gndCounter
  2165. ## puts $gndId
  2166. ## puts $gndTags
  2167. }
  2168. }
  2169. ########################################################################################
  2170. # Edit the parameters of the palette
  2171. ########################################################################################
  2172. proc Coption { w title flag } {
  2173. global paletteXsize paletteYsize Xscale Yscale
  2174. global pbottomleftX pbottomleftY
  2175. global tempdata1 tempdata2 tempdata3 tempdata4
  2176. global newFlag
  2177. if { $newFlag < 0 && $flag == 0 } {
  2178. promptInfo "You must setup a new palette first!"
  2179. return $newFlag
  2180. }
  2181. toplevel $w -class Dialog
  2182. wm title $w $title
  2183. wm iconname $w Dialog
  2184. frame $w.top -relief raised -bd 1
  2185. pack $w.top -side top -fill both
  2186. frame $w.bot -relief raised -bd 1
  2187. pack $w.bot -side bottom -fill both
  2188. set tempdata1 $paletteXsize
  2189. set tempdata2 $paletteYsize
  2190. set tempdata3 $pbottomleftX
  2191. set tempdata4 $pbottomleftY
  2192. grid [label $w.top.lab3 -text "Palette Size"] \
  2193. [entry $w.top.ent2 -textvariable paletteXsize] \
  2194. [label $w.top.lab4 -text "m"] -sticky e
  2195. grid [label $w.top.lab5 -text "Palette Bottomleft X Coord"] \
  2196. [entry $w.top.ent3 -textvariable pbottomleftX] -sticky e
  2197. grid [label $w.top.lab6 -text "Palette Bottomleft Y Coord"] \
  2198. [entry $w.top.ent4 -textvariable pbottomleftY] -sticky e
  2199. button $w.bot.buttonok -text "OK" -command {
  2200. set paletteYsize [expr {$paletteXsize/$maxXcoord*$maxYcoord }]
  2201. destroy .palettePara
  2202. optionOk
  2203. }
  2204. button $w.bot.buttoncancel -text "CANCEL" -command {
  2205. destroy .palettePara
  2206. set paletteXsize $tempdata1
  2207. set paletteYsize $tempdata2
  2208. set pbottomleftX $tempdata3
  2209. set pbottomleftY $tempdata4
  2210. }
  2211. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  2212. }
  2213. proc optionOk { } {
  2214. global maxXcoord maxYcoord
  2215. global paletteXsize paletteYsize Xscale Yscale
  2216. global pbottomleftX pbottomleftY
  2217. global palFlag
  2218. global myAppChangedFlag
  2219. if { $paletteXsize > 0 && $paletteYsize > 0 } {
  2220. set Xscale [ expr {$maxXcoord/$paletteXsize }]
  2221. ## puts "begin"
  2222. ## puts $maxXcoord
  2223. ## puts $paletteXsize
  2224. ## puts $Xscale
  2225. ## puts "end"
  2226. set Yscale [ expr {$maxYcoord/$paletteYsize }]
  2227. set palFlag 0
  2228. ## puts "OK"
  2229. }
  2230. }
  2231. proc calpara { w title } {
  2232. global paletteXsize paletteYsize Xscale Yscale
  2233. global pbottomleftX pbottomleftY
  2234. global tempdata1 tempdata2 tempdata3 tempdata4
  2235. global tempdata5 tempdata6 tempdata7 tempdata8
  2236. global tempdata9 tempdata10 tempdata11 tempdata12
  2237. global newFlag
  2238. global Nh Nit J
  2239. global Nwx Nwy Nws
  2240. global Np Eps matr
  2241. # global freq sigma
  2242. global od maxga
  2243. global myAppChangedFlag
  2244. if { $newFlag < 0 } {
  2245. promptInfo "You must setup a new palette first!"
  2246. return $newFlag
  2247. }
  2248. toplevel $w -class Dialog
  2249. wm title $w $title
  2250. wm iconname $w Dialog
  2251. frame $w.top -relief raised -bd 1
  2252. pack $w.top -side top -fill both
  2253. frame $w.bot -relief raised -bd 1
  2254. pack $w.bot -side bottom -fill both
  2255. set tempdata1 $Nh
  2256. set tempdata2 $Nit
  2257. set tempdata3 $J
  2258. set tempdata4 $Nwx
  2259. set tempdata5 $Nwy
  2260. set tempdata6 $Nws
  2261. set tempdata7 $Np
  2262. set tempdata8 $Eps
  2263. set tempdata9 $matr
  2264. set tempdata10 $od
  2265. set tempdata11 $maxga
  2266. grid [label $w.top.lab3 -text "Wavelet Point Number"] \
  2267. [entry $w.top.ent2 -textvariable Nh] -sticky e
  2268. grid [label $w.top.lab4 -text "Number of Iteration"] \
  2269. [entry $w.top.ent3 -textvariable Nit] -sticky e
  2270. grid [label $w.top.lab5 -text "Resolution Level"] \
  2271. [entry $w.top.ent4 -textvariable J] -sticky e
  2272. grid [label $w.top.lab6 -text "Gauss Quadrature X"] \
  2273. [entry $w.top.ent5 -textvariable Nwx] -sticky e
  2274. grid [label $w.top.lab7 -text "Gauss Quadrature Y"] \
  2275. [entry $w.top.ent6 -textvariable Nwy] -sticky e
  2276. grid [label $w.top.lab8 -text "Number of Segments/Wavelet"] \
  2277. [entry $w.top.ent7 -textvariable Nws] -sticky e
  2278. grid [label $w.top.lab9 -text "OPQ Seperation"] \
  2279. [entry $w.top.ent8 -textvariable Np] -sticky e
  2280. grid [label $w.top.lab10 -text "STAB Accuracy"] \
  2281. [entry $w.top.ent9 -textvariable Eps] -sticky e
  2282. grid [label $w.top.lab11 -text "Matrix Solution"] \
  2283. [entry $w.top.ent10 -textvariable matr] -sticky e
  2284. grid [label $w.top.lab12 -text "Order of appoximation"] \
  2285. [entry $w.top.ent11 -textvariable od] -sticky e
  2286. grid [label $w.top.lab13 -text "Maximum approximation range"] \
  2287. [entry $w.top.ent12 -textvariable maxga] -sticky e
  2288. button $w.bot.buttonok -text "OK" -command {
  2289. set myAppChangedFlag 1
  2290. destroy .calPara
  2291. }
  2292. button $w.bot.buttoncancel -text "CANCEL" -command {
  2293. destroy .calPara
  2294. set Nh $tempdata1
  2295. set Nit $tempdata2
  2296. set J $tempdata3
  2297. set Nwx $tempdata4
  2298. set Nwy $tempdata5
  2299. set Nws $tempdata6
  2300. set Np $tempdata7
  2301. set Eps $tempdata8
  2302. set matr $tempdata9
  2303. set od $tempdata10
  2304. set maxga $tempdata11
  2305. }
  2306. pack $w.bot.buttonok $w.bot.buttoncancel -side left -fill both
  2307. }
  2308. ########################################################################################
  2309. # Check if the palette parameters have been setup
  2310. ########################################################################################
  2311. proc checkPal { } {
  2312. global maxXcoord maxYcoord
  2313. global paletteXsize paletteYsize Xscale Yscale
  2314. global pbottomleftX pbottomleftY
  2315. global palFlag
  2316. if { $paletteXsize > 0 && $paletteYsize > 0 } {
  2317. set palFlag 0
  2318. } else {
  2319. set palFlag -1
  2320. toplevel .prompted -class Dialog
  2321. wm title .prompted "error"
  2322. wm iconname .prompted Dialog
  2323. frame .prompted.top -relief raised -bd 1
  2324. pack .prompted.top -side top -fill both
  2325. message .prompted.msg -width 8c -justify left -relief flat -bd 2 \
  2326. -text "You must input the palette parameters first."
  2327. button .prompted.okbutton -text "OK" -command { destroy .prompted }
  2328. pack .prompted.msg .prompted.okbutton -side top -padx 2m -pady 2m
  2329. }
  2330. return $palFlag
  2331. }
  2332. proc promptInfo { message } {
  2333. toplevel .prompted -class Dialog -width 400
  2334. wm title .prompted "Info"
  2335. wm iconname .prompted Dialog
  2336. frame .prompted.top -relief raised -bd 1
  2337. pack .prompted.top -side top -expand yes -fill both
  2338. puts "message: $message"
  2339. set txt [text .prompted.msg -width 40]
  2340. $txt insert end $message
  2341. ## message .prompted.msg -anchor c -relief flat -bd 2 \
  2342. ## -text $message
  2343. button .prompted.okbutton -text "OK" -command { destroy .prompted }
  2344. pack .prompted.msg .prompted.okbutton -side top -expand yes -fill x
  2345. }
  2346. ########################################################################################
  2347. # Update data package after deleting and adding new components
  2348. ########################################################################################
  2349. proc updateData { } {
  2350. }
  2351. ########################################################################################
  2352. #--------------------------------------------------
  2353. #
  2354. # File Procedures
  2355. #
  2356. # Note that opening, saving, and closing files
  2357. # are all intertwined. This code assumes that
  2358. # new/open/close/exit may lose some data.
  2359. #
  2360. #--------------------------------------------------
  2361. global myAppFileTypes
  2362. set myAppFileName ""
  2363. set myAppChangedFlag 0
  2364. set myAppFileTypes {
  2365. {{data files} {.dat} }
  2366. {{tcl files} {.tcl .tk} }
  2367. {{text files} {.txt} }
  2368. {{All Files} * }
  2369. }
  2370. proc myAppFileNew { } {
  2371. global myAppFileName
  2372. global myAppChangedFlag
  2373. global myAppFileTypes
  2374. global newFlag
  2375. global palFlag
  2376. global paletteXsize paletteYsize
  2377. myAppFileClose
  2378. set filename [ tk_getSaveFile -filetypes $myAppFileTypes \
  2379. -initialdir "."]
  2380. ## puts "file: $filename"
  2381. if {$filename != ""} {
  2382. set indx [string first ".dat" $filename]
  2383. if { $indx > -1 } {
  2384. set myAppFileName [string range $filename 0 [expr {($indx - 1) }]]
  2385. } else {
  2386. set myAppFileName $filename
  2387. }
  2388. }
  2389. Coption .palettePara { Palette Parameters } 1
  2390. tkwait window .palettePara
  2391. if { $palFlag == 0 } {
  2392. initc 0
  2393. .c configure -background gray
  2394. .dummy.statusCon configure -text "Your have setup a new file named tempfile"
  2395. set newFlag 0
  2396. set myAppFileName ""
  2397. set myAppChangedFlag 0
  2398. }
  2399. }
  2400. proc myAppFileOpen { {filename ""} } {
  2401. global myAppFileName
  2402. global myAppChangedFlag
  2403. global myAppFileTypes
  2404. global fileHead
  2405. global dieleData recData cirData triData ellData polyData gndData
  2406. global recCounter cirCounter dieleCounter ellCounter triCounter polyCounter \
  2407. gndCounter
  2408. global recTags cirTags dieleTags ellTags triTags polyTags gndTags
  2409. global recId cirId dieleId ellId triId polyId gndId
  2410. global maxXcoord maxYcoord
  2411. global paletteXsize paletteYsize Xscale Yscale
  2412. global pbottomleftX pbottomleftY
  2413. global newFlag
  2414. global Nh Nit J
  2415. global Nwx Nwy Nws
  2416. global Np Eps matr
  2417. global od maxga
  2418. myAppFileClose
  2419. if {$filename == ""} {
  2420. set filename [tk_getOpenFile -filetypes $myAppFileTypes]
  2421. }
  2422. if {$filename != ""} {
  2423. set indx [string first ".dat" $filename]
  2424. if { $indx > -1 } {
  2425. set myAppFileName [string range $filename 0 [expr {($indx - 1) }]]
  2426. } else {
  2427. set myAppFileName $filename
  2428. }
  2429. puts "Open: $myAppFileName.dat"
  2430. if { [catch {open $filename r} fp] } {
  2431. error "Cannot Open File $filename for Reading"
  2432. } else {
  2433. #--------------------------------------------------
  2434. # insert code for "open" operation
  2435. #--------------------------------------------------
  2436. ### .t insert end [read $fp [file size $filename]]
  2437. # need to read the data, redraw them on the palette and
  2438. # renew the Id number in xxxID and xxxData, renew counter.
  2439. # So just redraw all of them
  2440. set newFlag 0
  2441. .c configure -background gray
  2442. gets $fp paletteXsize
  2443. gets $fp paletteYsize
  2444. gets $fp Xscale
  2445. gets $fp Yscale
  2446. gets $fp pbottomleftX
  2447. gets $fp pbottomleftY
  2448. gets $fp Nh
  2449. gets $fp Nit
  2450. gets $fp J
  2451. gets $fp Nwx
  2452. gets $fp Nwy
  2453. gets $fp Nws
  2454. gets $fp Np
  2455. gets $fp Eps
  2456. gets $fp matr
  2457. gets $fp od
  2458. gets $fp maxga
  2459. gets $fp tempfileHead
  2460. gets $fp tempdieleData
  2461. gets $fp temprecData
  2462. gets $fp tempcirData
  2463. gets $fp temptriData
  2464. gets $fp tempellData
  2465. gets $fp temppolyData
  2466. gets $fp tempgndData
  2467. set curNum [lindex $tempfileHead 0]
  2468. for {set counter 0} {$counter < $curNum} {incr counter} {
  2469. set corFlag -1
  2470. set dielex [lindex $tempdieleData [expr {$counter*9+4 }]]
  2471. set dieley [lindex $tempdieleData [expr {$counter*9+5 }]]
  2472. set dielew [lindex $tempdieleData [expr {$counter*9+6 }]]
  2473. set dieleh [lindex $tempdieleData [expr {$counter*9+7 }]]
  2474. set dielepermit [lindex $tempdieleData [expr {$counter*9+8 }]]
  2475. dieleOk $dielex $dieley $dielew $dieleh $dielepermit {}
  2476. }
  2477. set curNum [lindex $tempfileHead 1]
  2478. for {set counter 0} {$counter < $curNum} {incr counter} {
  2479. set corFlag -1
  2480. set recx [lindex $temprecData [expr {$counter*8+4 }]]
  2481. set recy [lindex $temprecData [expr {$counter*8+5 }]]
  2482. set recw [lindex $temprecData [expr {$counter*8+6 }]]
  2483. set rech [lindex $temprecData [expr {$counter*8+7 }]]
  2484. rectOk $recx $recy $recw $rech {}
  2485. }
  2486. puts "circle: $tempcirData"
  2487. set curNum [lindex $tempfileHead 2]
  2488. for {set counter 0} {$counter < $curNum} {incr counter} {
  2489. set corFlag -1
  2490. set cirx [lindex $tempcirData [expr {$counter*7+4 }]]
  2491. set ciry [lindex $tempcirData [expr {$counter*7+5 }]]
  2492. set cirr [lindex $tempcirData [expr {$counter*7+6 }]]
  2493. puts "circle: ($cirx,$ciry) $cirr"
  2494. cirOk $cirx $ciry $cirr {}
  2495. }
  2496. set curNum [lindex $tempfileHead 3]
  2497. for {set counter 0} {$counter < $curNum} {incr counter} {
  2498. set corFlag -1
  2499. set tri1x [lindex $temptriData [expr {$counter*10+4 }]]
  2500. set tri1y [lindex $temptriData [expr {$counter*10+5 }]]
  2501. set tri2x [lindex $temptriData [expr {$counter*10+6 }]]
  2502. set tri2y [lindex $temptriData [expr {$counter*10+7 }]]
  2503. set tri3x [lindex $temptriData [expr {$counter*10+8 }]]
  2504. set tri3y [lindex $temptriData [expr {$counter*10+9 }]]
  2505. triOk $tri1x $tri1y $tri2x $tri2y $tri3x $tri3y {}
  2506. }
  2507. set curNum [lindex $tempfileHead 4]
  2508. for {set counter 0} {$counter < $curNum} {incr counter} {
  2509. set corFlag -1
  2510. set ellx [lindex $tempellData [expr {$counter*8+4 }]]
  2511. set elly [lindex $tempellData [expr {$counter*8+5 }]]
  2512. set ellma [lindex $tempellData [expr {$counter*8+6 }]]
  2513. set ellmi [lindex $tempellData [expr {$counter*8+7 }]]
  2514. ellOk $ellx $elly $ellma $ellmi {}
  2515. }
  2516. set curNum [lindex $tempfileHead 5]
  2517. ## puts "tempfileHead: $tempfileHead $curNum"
  2518. ## puts "temppolyData: $temppolyData"
  2519. if {$curNum > 0} {
  2520. for {set counter 0} {$counter < $curNum} {incr counter} {
  2521. set corFlag -1
  2522. if { [lsearch $temppolyData POLY] == 0 } {
  2523. ## puts "hhh"
  2524. set tempapexnum [lindex $temppolyData 4]
  2525. ## puts $tempapexnum
  2526. set tempapex {}
  2527. for { set i 1 } { $i <= $tempapexnum } {incr i} {
  2528. lappend tempapex [expr {([lindex $temppolyData [expr {3+2*$i }]] \
  2529. -$pbottomleftX)*$Xscale }]
  2530. lappend tempapex [expr {$maxYcoord-([lindex $temppolyData \
  2531. [expr {4+2*$i }]]-$pbottomleftY)*$Yscale }]
  2532. }
  2533. }
  2534. #---------------------------------------------------------------------
  2535. # Fix so more than one polygon can be read into the program. skz (2/19/2002)
  2536. #---------------------------------------------------------------------
  2537. #### set temppolyData [lreplace $temppolyData 0 [expr {5+2*$tempapexnum }]]
  2538. set temppolyData [string range $temppolyData 4 [expr { [string length $temppolyData] - 1 }]]
  2539. set indx [string first POLY $temppolyData]
  2540. if { $indx > 0 } {
  2541. set temppolyData [string range $temppolyData $indx [expr { [string length $temppolyData] - 1 }]]
  2542. }
  2543. ## puts $tempapex
  2544. ## puts $temppolyData
  2545. puts "tempapex: $tempapex"
  2546. polyOk $tempapex {}
  2547. }
  2548. }
  2549. set curNum [lindex $tempfileHead 6]
  2550. for {set counter 0} {$counter < $curNum} {incr counter} {
  2551. set corFlag -1
  2552. set gndx [lindex $tempgndData [expr {$counter*8+4 }]]
  2553. set gndy [lindex $tempgndData [expr {$counter*8+5 }]]
  2554. set gndw [lindex $tempgndData [expr {$counter*8+6 }]]
  2555. set gndh [lindex $tempgndData [expr {$counter*8+7 }]]
  2556. gndOk $gndx $gndy $gndw $gndh {}
  2557. }
  2558. }
  2559. close $fp
  2560. ## set myAppFileName $filename
  2561. set myAppChangedFlag 0
  2562. }
  2563. }
  2564. proc myAppFileClose { } {
  2565. global myAppFileName
  2566. global myAppChangedFlag
  2567. if { $myAppChangedFlag } {
  2568. myAppPromptForSave
  2569. }
  2570. delall
  2571. initc 1
  2572. .c configure -background black
  2573. #--------------------------------------------------
  2574. # insert code for "close" operation
  2575. #--------------------------------------------------
  2576. ### .t delete 1.0 end
  2577. set myAppFileName ""
  2578. set myAppChangedFlag 0
  2579. }
  2580. proc myAppFileSave { {filename ""} } {
  2581. global myAppFileName
  2582. global myAppFileTypes
  2583. global myAppChangedFlag
  2584. global fileHead
  2585. global dieleData recData cirData triData ellData polyData gndData
  2586. global recCounter cirCounter dieleCounter ellCounter triCounter polyCounter \
  2587. gndCounter
  2588. global recTags cirTags dieleTags ellTags triTags polyTags gndTags
  2589. global recId cirId dieleId ellId triId polyId gndId
  2590. global maxXcoord maxYcoord
  2591. global paletteXsize paletteYsize Xscale Yscale
  2592. global pbottomleftX pbottomleftY
  2593. global Nh Nit J
  2594. global Nwx Nwy Nws
  2595. global Np Eps matr
  2596. global od maxga
  2597. if { $filename == "" && $myAppFileName != "" } {
  2598. set filename $myAppFileName
  2599. } elseif { $filename == "" && $myAppFileName == "" } {
  2600. set filename [tk_getSaveFile -filetypes $myAppFileTypes]
  2601. if { $filename != "" } {
  2602. set myAppFileName $filename
  2603. }
  2604. }
  2605. puts "Save: $myAppFileName.in"
  2606. if { $filename != "" } {
  2607. set fullfilename [format "%s.in" $myAppFileName]
  2608. if { [catch {open $filename w+ } fp] } {
  2609. error "Cannot write to $filename"
  2610. }
  2611. puts $fp $paletteXsize
  2612. puts $fp $paletteYsize
  2613. puts $fp $Xscale
  2614. puts $fp $Yscale
  2615. puts $fp $pbottomleftX
  2616. puts $fp $pbottomleftY
  2617. puts $fp $Nh
  2618. puts $fp $Nit
  2619. puts $fp $J
  2620. puts $fp $Nwx
  2621. puts $fp $Nwy
  2622. puts $fp $Nws
  2623. puts $fp $Np
  2624. puts $fp $Eps
  2625. puts $fp $matr
  2626. puts $fp $od
  2627. puts $fp $maxga
  2628. puts $fp $fileHead
  2629. puts $fp $dieleData
  2630. puts $fp $recData
  2631. puts $fp $cirData
  2632. puts $fp $triData
  2633. puts $fp $ellData
  2634. puts $fp $polyData
  2635. puts $fp $gndData
  2636. #--------------------------------------------------
  2637. # insert code for "save" operation
  2638. #--------------------------------------------------
  2639. ### puts -nonewline [.t get 1.0 end]
  2640. close $fp
  2641. set myAppFileName $filename
  2642. set myAppChangedFlag 0
  2643. }
  2644. }
  2645. proc myAppFileSaveAs { } {
  2646. global myAppFileTypes
  2647. set filename [tk_getSaveFile -filetypes $myAppFileTypes]
  2648. if { $filename != "" } {
  2649. set myAppFileName $filename
  2650. myAppFileSave $filename
  2651. }
  2652. }
  2653. proc myAppPromptForSave { } {
  2654. set answer [tk_messageBox -title "save?" -type yesno -icon question -message "Do you want to save the changes?"]
  2655. if { $answer == "yes" } {
  2656. myAppFileSaveAs
  2657. }
  2658. }
  2659. proc myAppExit { } {
  2660. myAppFileClose
  2661. exit
  2662. }
  2663. #########################################################################
  2664. # NAME: about
  2665. # PURPOSE: show the about information including name and version
  2666. #
  2667. #########################################################################
  2668. proc about {} {
  2669. # tk_messageBox -message "Muti-conductor Parameters Computation \n Electric Packaging Lab.\n Arizona State University\n 2000.8"
  2670. promptInfo " Capacitance Calculation of\n Multiconductor Lines \n\n\n Copyright 2001.05 EPL\n Electric Packaging Lab.\nElectrical Engineering Dept. \n Arizona State University\n\n 2001.05"
  2671. }
  2672. proc viewreadme {} {
  2673. exec emacs readme &
  2674. }
  2675. proc eplIntro {} {
  2676. promptInfo "This program is developed by\n\n Electric Packaging Lab\n Eletrical Engineering Dept. \n Arizona State University \n\n Tel: (480)965-7048\n http://quantum.eas.asu.edu\n"
  2677. }
  2678. proc printPara {} {
  2679. global newFlag
  2680. global pData
  2681. if { $newFlag < 0 } {
  2682. promptInfo "You must setup a new palette first!"
  2683. return $newFlag
  2684. }
  2685. setdata
  2686. ## puts $pData
  2687. exec lpr <<$pData &
  2688. }
  2689. proc printcal {} {
  2690. global newFlag
  2691. global pcal
  2692. if { $newFlag < 0 } {
  2693. promptInfo "You must setup a new palette first!"
  2694. return $newFlag
  2695. }
  2696. caldata
  2697. ## puts $pcal
  2698. exec lpr <<$pcal &
  2699. }
  2700. proc printGraph {} {
  2701. global myAppFileName
  2702. global maxXcoord maxYcoord
  2703. set pssurfix ".ps"
  2704. if { $myAppFileName != "" } {
  2705. set pssurfix $myAppFileName$pssurfix
  2706. } else {
  2707. promptInfo "You must save the palette first!"
  2708. return -1
  2709. }
  2710. .c create rectangle 0 0 [expr {$maxXcoord-1 }] [expr {$maxYcoord-1 }] \
  2711. -outline black -tags printframe
  2712. set psFlag [.c postscript -width 24c -height 16c -colormode gray -file $pssurfix -rotate 1]
  2713. .c delete printframe
  2714. if { $psFlag == "" } {
  2715. exec lpr $pssurfix &
  2716. } else {
  2717. promptInfo "The Postscript file can not be generated!"
  2718. return -1
  2719. }
  2720. }
  2721. proc setTag { id idArray tagArray dataArray } {
  2722. global curPosition
  2723. set tempPosition [lsearch -exact $idArray $id]
  2724. set tempTag [lindex $tagArray $tempPosition]
  2725. set curPosition [lsearch -exact $dataArray $tempTag]
  2726. return $curPosition
  2727. }
  2728. ##############################################
  2729. # Test
  2730. ##############################################
  2731. proc startcal1 { flag } {
  2732. global env
  2733. global fileHead
  2734. global myAppFileName
  2735. global dieleData recData cirData triData ellData polyData gndData
  2736. global newFlag
  2737. global pData pcal
  2738. global Nh Nit J
  2739. global Nwx Nwy Nws
  2740. global Np Eps matr
  2741. global od maxga
  2742. ## puts "newFlag $newFlag"
  2743. ## puts "hhh"
  2744. if { $newFlag < 0 } {
  2745. promptInfo "You must setup a new palette first!"
  2746. return $newFlag
  2747. }
  2748. set fileId [ open "$myAppFileName.in" w+ ]
  2749. set gndnumber [lindex $fileHead 6]
  2750. set recnumber [lindex $fileHead 1]
  2751. set cirnumber [lindex $fileHead 2]
  2752. set tranumber [lindex $fileHead 5]
  2753. set dienumber [lindex $fileHead 0]; # number of dielectric layers
  2754. puts $fileId $gndnumber
  2755. puts $fileId $recnumber
  2756. puts $fileId $cirnumber
  2757. puts $fileId $tranumber
  2758. puts $fileId $dienumber; #
  2759. if { $gndnumber > 0 } {
  2760. for { set i 1 } { $i <= $gndnumber } {incr i} {
  2761. puts $fileId [lindex $gndData [expr {($i-1)*8+4 }]]
  2762. puts $fileId [lindex $gndData [expr {($i-1)*8+5 }]]
  2763. puts $fileId [lindex $gndData [expr {($i-1)*8+6 }]]
  2764. puts $fileId [lindex $gndData [expr {($i-1)*8+7 }]]
  2765. }
  2766. }
  2767. if { $recnumber > 0 } {
  2768. for { set i 1 } { $i <= $recnumber } {incr i} {
  2769. puts $fileId [lindex $recData [expr {($i-1)*8+4 }]]
  2770. puts $fileId [lindex $recData [expr {($i-1)*8+5 }]]
  2771. puts $fileId [lindex $recData [expr {($i-1)*8+6 }]]
  2772. puts $fileId [lindex $recData [expr {($i-1)*8+7 }]]
  2773. }
  2774. }
  2775. if { $cirnumber > 0 } {
  2776. for { set i 1 } { $i <= $cirnumber } {incr i} {
  2777. puts $fileId [lindex $cirData [expr {($i-1)*7+4 }]]
  2778. puts $fileId [lindex $cirData [expr {($i-1)*7+5 }]]
  2779. puts $fileId [lindex $cirData [expr {($i-1)*7+6 }]]
  2780. }
  2781. }
  2782. if { $tranumber > 0 } {
  2783. for { set i 1 } { $i <= $tranumber } {incr i} {
  2784. puts $fileId [lindex $polyData [expr {($i-1)*13+5 }]]
  2785. puts $fileId [lindex $polyData [expr {($i-1)*13+6 }]]
  2786. puts $fileId [lindex $polyData [expr {($i-1)*13+7 }]]
  2787. puts $fileId [lindex $polyData [expr {($i-1)*13+8 }]]
  2788. puts $fileId [lindex $polyData [expr {($i-1)*13+9 }]]
  2789. puts $fileId [lindex $polyData [expr {($i-1)*13+10 }]]
  2790. puts $fileId [lindex $polyData [expr {($i-1)*13+11 }]]
  2791. puts $fileId [lindex $polyData [expr {($i-1)*13+12 }]]
  2792. }
  2793. }
  2794. if { $dienumber > 0 } {
  2795. for { set i 1 } { $i <= $dienumber } {incr i} {
  2796. puts $fileId [lindex $dieleData [expr {($i-1)*9+4 }]]
  2797. puts $fileId [lindex $dieleData [expr {($i-1)*9+5 }]]
  2798. puts $fileId [lindex $dieleData [expr {($i-1)*9+6 }]]
  2799. puts $fileId [lindex $dieleData [expr {($i-1)*9+7 }]]
  2800. puts $fileId [lindex $dieleData [expr {($i-1)*9+8 }]]
  2801. }
  2802. }
  2803. puts $fileId $Nh
  2804. puts $fileId $Nit
  2805. puts $fileId $J
  2806. puts $fileId $Nwx
  2807. puts $fileId $Nwy
  2808. puts $fileId $Nws
  2809. puts $fileId $Np
  2810. puts $fileId $Eps
  2811. puts $fileId $matr
  2812. puts $fileId $od
  2813. puts $fileId $maxga
  2814. close $fileId
  2815. ## puts $flag
  2816. if {$flag == 1} {
  2817. setdata
  2818. caldata
  2819. #set fp [ open "/users/zhichao/tcltk/cal/caldata.sys" w+ ]
  2820. set fp [ open "caldata.sys" w+ ]
  2821. puts $fp $pData
  2822. puts $fp $pcal
  2823. close $fp
  2824. #exec xemacs "/users/zhichao/tcltk/cal/caldata.sys" &
  2825. exec emacs "caldata.sys" &
  2826. } elseif {$flag == 2} {
  2827. #---------------------------------------------------------
  2828. # Change the cursor to a watch and run calcCAP.exe
  2829. #---------------------------------------------------------
  2830. set cursr [.c cget -cursor]
  2831. .mbar configure -cursor watch
  2832. .c configure -cursor watch
  2833. update
  2834. set hd [catch { eval exec $env(CALCCAP_LIBRARY)/calcCAP \
  2835. $myAppFileName} result]
  2836. puts $result
  2837. #---------------------------------------------------------
  2838. # Change the curso back to the normal cursor.
  2839. #---------------------------------------------------------
  2840. .mbar configure -cursor $cursr
  2841. .c configure -cursor $cursr
  2842. update
  2843. checkResult
  2844. }
  2845. }
  2846. proc checkResult { } {
  2847. global myAppFileName
  2848. #exec xemacs /users/zhichao/tcltk/cal/data.out &
  2849. eval exec emacs $myAppFileName.out &
  2850. }
  2851. proc killpro { hd } {
  2852. global pid
  2853. toplevel .apexwindow -class Dialog
  2854. wm title .apexwindow "Calculation"
  2855. wm iconname .apexwindow Dialog
  2856. frame .apexwindow.textframe -width 10c -height 6c
  2857. frame .apexwindow.buttonframe -width 10c -height 2c
  2858. label .apexwindow.textframe.label -text "In Calculation, Please wait..."
  2859. set pid $hd
  2860. button .apexwindow.buttonframe.bbutton -text Break -command {
  2861. exec kill -9 $pid
  2862. destroy .apexwindow
  2863. }
  2864. pack .apexwindow.textframe .apexwindow.buttonframe -side top -padx 1m -pady 2m
  2865. pack .apexwindow.textframe.label -side left -padx 1m -pady 2m
  2866. pack .apexwindow.buttonframe.bbutton \
  2867. -side left -padx 1m -pady 2m
  2868. }
  2869. proc setdata { } {
  2870. global fileHead
  2871. global dieleData recData cirData triData ellData polyData gndData
  2872. global newFlag
  2873. global pData
  2874. set gndnumber [lindex $fileHead 6]
  2875. set recnumber [lindex $fileHead 1]
  2876. set cirnumber [lindex $fileHead 2]
  2877. set tranumber [lindex $fileHead 5]
  2878. set dienumber [lindex $fileHead 0]
  2879. set nl "\n"
  2880. set sp " "
  2881. set sp1 " "
  2882. set sp5 " "
  2883. set sep " -------------------------------------"
  2884. set hh " The Geometrical Parameters"
  2885. set dn " Dielectric Number:"
  2886. set gn " Ground Number:"
  2887. set rn " Rectangle Number:"
  2888. set cn " Circle Number:"
  2889. set tn " Trapezoid Number:"
  2890. set h0 " DIELETRIC"
  2891. set h1 " GROUND PLANE"
  2892. set h2 " RECTANGLE"
  2893. set h3 " CIRCLE"
  2894. set h4 " TRAPEZOID"
  2895. set r1 " lowerleft x:"
  2896. set r2 " lowerleft y:"
  2897. set r3 " width:"
  2898. set r4 " height:"
  2899. set c1 " center x:"
  2900. set c2 " center y:"
  2901. set c3 " radius:"
  2902. set t1 " apex x"
  2903. set t2 " apex y"
  2904. set t3 ":"
  2905. set c " current:"
  2906. set er " epsr:"
  2907. set pData $nl$sep$nl$hh$nl$sep$nl$nl
  2908. set pData $pData$dn$sp$dienumber$nl$nl
  2909. set pData $pData$gn$sp$gndnumber$nl
  2910. set pData $pData$rn$sp$recnumber$nl
  2911. set pData $pData$cn$sp$cirnumber$nl
  2912. set pData $pData$tn$sp$tranumber$nl$nl$sep$nl
  2913. if { $dienumber > 0 } {
  2914. for { set i 1 } { $i <= $dienumber } { incr i } {
  2915. set pData $pData$h0$i$nl$nl
  2916. set pData $pData$r1$sp[lindex $dieleData [expr {($i-1)*9+4 }]]$nl
  2917. set pData $pData$r2$sp[lindex $dieleData [expr {($i-1)*9+5 }]]$nl
  2918. set pData $pData$r3$sp[lindex $dieleData [expr {($i-1)*9+6 }]]$nl
  2919. set pData $pData$r4$sp[lindex $dieleData [expr {($i-1)*9+7 }]]$nl
  2920. set pData $pData$sp5$er$sp[lindex $dieleData [expr {($i-1)*9+8 }]]$nl
  2921. set pData $pData$nl
  2922. }
  2923. set pData $pData$sep$nl
  2924. }
  2925. if { $gndnumber > 0 } {
  2926. for { set i 1 } { $i <= $gndnumber } { incr i } {
  2927. set pData $pData$h1$i$nl$nl
  2928. set pData $pData$r1$sp[lindex $gndData [expr {($i-1)*8+4 }]]$nl
  2929. set pData $pData$r2$sp[lindex $gndData [expr {($i-1)*8+5 }]]$nl
  2930. set pData $pData$r3$sp[lindex $gndData [expr {($i-1)*8+6 }]]$nl
  2931. set pData $pData$r4$sp[lindex $gndData [expr {($i-1)*8+7 }]]$nl
  2932. #set pData $pData$sp5$c$sp[lindex $gndData [expr {($i-1)*9+8 }]]$nl
  2933. set pData $pData$nl
  2934. }
  2935. set pData $pData$sep$nl
  2936. }
  2937. if { $recnumber > 0 } {
  2938. for { set i 1 } { $i <= $recnumber } { incr i } {
  2939. set pData $pData$h2$i$nl$nl
  2940. set pData $pData$r1$sp[lindex $recData [expr {($i-1)*8+4 }]]$nl
  2941. set pData $pData$r2$sp[lindex $recData [expr {($i-1)*8+5 }]]$nl
  2942. set pData $pData$r3$sp[lindex $recData [expr {($i-1)*8+6 }]]$nl
  2943. set pData $pData$r4$sp[lindex $recData [expr {($i-1)*8+7 }]]$nl
  2944. #set pData $pData$sp5$c$sp[lindex $recData [expr {($i-1)*9+8 }]]$nl
  2945. set pData $pData$nl
  2946. }
  2947. set pData $pData$sep$nl
  2948. }
  2949. if { $cirnumber > 0 } {
  2950. for { set i 1 } { $i <= $cirnumber } { incr i } {
  2951. set pData $pData$h3$i$nl$nl
  2952. set pData $pData$c1$sp[lindex $cirData [expr {($i-1)*7+4 }]]$nl
  2953. set pData $pData$c2$sp[lindex $cirData [expr {($i-1)*7+5 }]]$nl
  2954. set pData $pData$c3$sp[lindex $cirData [expr {($i-1)*7+6 }]]$nl
  2955. #set pData $pData$sp1$c$sp[lindex $cirData [expr {($i-1)*8+7 }]]$nl
  2956. set pData $pData$nl
  2957. }
  2958. set pData $pData$sep$nl
  2959. }
  2960. if { $tranumber > 0 } {
  2961. for { set i 1 } { $i <= $tranumber } { incr i } {
  2962. set pData $pData$h4$i$nl$nl
  2963. for { set j 1 } { $j <= 4 } { incr j } {
  2964. set pData $pData$t1[expr {$j }]$t3$sp[lindex $polyData [expr {($i-1)*13+3+$j*2 }]]$nl
  2965. set pData $pData$t2[expr {$j }]$t3$sp[lindex $polyData [expr {($i-1)*13+4+$j*2 }]]$nl
  2966. }
  2967. #set pData $pData$c$sp[lindex $polyData [expr {($i-1)*14+13 }]]$nl
  2968. set pData $pData$nl
  2969. }
  2970. }
  2971. }
  2972. proc caldata { } {
  2973. global Nh Nit J
  2974. global Nwx Nwy Nws
  2975. global Np Eps matr
  2976. global od maxga
  2977. global pcal
  2978. set t1 " Wavelet Point Number:"
  2979. set t2 " Number of Iteration:"
  2980. set t3 " Resolution Level:"
  2981. set t4 " Gauss Quadrature X:"
  2982. set t5 " Gauss Quadrature Y:"
  2983. set t6 " \# of Segments/Wavelet:"
  2984. set t7 " OPQ Seperation:"
  2985. set t8 " STAB Accuracy:"
  2986. set t9 " Matrix Solution:"
  2987. set t10 " Order of Approximation"
  2988. set t11 " Approximation Range"
  2989. set nl "\n"
  2990. set sp " "
  2991. set sep " -------------------------------------"
  2992. set hh " The Calculation Parameters"
  2993. set pcal $nl$sep$nl$hh$nl$sep$nl$nl
  2994. set pcal $pcal$t1$sp$Nh$nl
  2995. set pcal $pcal$t2$sp$Nit$nl
  2996. set pcal $pcal$t3$sp$J$nl
  2997. set pcal $pcal$t4$sp$Nwx$nl
  2998. set pcal $pcal$t5$sp$Nwy$nl
  2999. set pcal $pcal$t6$sp$Nws$nl
  3000. set pcal $pcal$t7$sp$Np$nl
  3001. set pcal $pcal$t8$sp$Eps$nl
  3002. set pcal $pcal$t9$sp$matr$nl
  3003. set pcal $pcal$t10$sp$od$nl
  3004. set pcal $pcal$t11$sp$maxga$nl
  3005. }
  3006. proc delall { } {
  3007. global fileHead
  3008. global recTags cirTags dieleTags ellTags triTags polyTags gndTags
  3009. set gndnumber [lindex $fileHead 6]
  3010. set recnumber [lindex $fileHead 1]
  3011. set cirnumber [lindex $fileHead 2]
  3012. set tranumber [lindex $fileHead 5]
  3013. set dienumber [lindex $fileHead 0]
  3014. if { $dienumber > 0 } {
  3015. for { set i 0 } { $i < $dienumber } {incr i} {
  3016. .c delete [lindex $dieleTags $i]
  3017. }
  3018. }
  3019. if { $gndnumber > 0 } {
  3020. for { set i 0 } { $i < $gndnumber } {incr i} {
  3021. .c delete [lindex $gndTags $i]
  3022. }
  3023. }
  3024. if { $recnumber > 0 } {
  3025. for { set i 0 } { $i < $recnumber } {incr i} {
  3026. .c delete [lindex $recTags $i]
  3027. }
  3028. }
  3029. if { $cirnumber > 0 } {
  3030. for { set i 0 } { $i < $cirnumber } {incr i} {
  3031. .c delete [lindex $cirTags $i]
  3032. }
  3033. }
  3034. if { $tranumber > 0 } {
  3035. for { set i 0 } { $i < $tranumber } {incr i} {
  3036. .c delete [lindex $polyTags $i]
  3037. }
  3038. }
  3039. }
  3040. proc initc { flag } {
  3041. global fileHead;# the number of each kind of conductor and dielectric
  3042. global dieleData recData cirData triData ellData polyData gndData
  3043. # global variables for saving all parameters of each kind
  3044. global palFlag
  3045. global corFlag
  3046. global newFlag
  3047. global recCounter cirCounter dieleCounter ellCounter triCounter polyCounter \
  3048. gndCounter
  3049. global recTags cirTags dieleTags ellTags triTags polyTags gndTags
  3050. global recId cirId dieleId ellId triId polyId gndId
  3051. global maxXcoord maxYcoord
  3052. global paletteXsize paletteYsize Xscale Yscale
  3053. global pbottomleftX pbottomleftY
  3054. global Nh Nit J
  3055. global Nwx Nwy Nws
  3056. global Np Eps matr
  3057. global od maxga
  3058. global pData pcal
  3059. set fileHead { 0 0 0 0 0 0 0 }; # dieleNum recNum cirNum triNum ellNum polyNum gndNum
  3060. set corFlag -1
  3061. set newFlag -1
  3062. set recCounter 0
  3063. set cirCounter 0
  3064. set dieleCounter 0
  3065. set ellCounter 0
  3066. set triCounter 0
  3067. set polyCounter 0
  3068. set gndCounter 0
  3069. set recId ""
  3070. set cirId ""
  3071. set dieleId ""
  3072. set ellId ""
  3073. set triId ""
  3074. set polyId ""
  3075. set gndId ""
  3076. set recData ""
  3077. set cirData ""
  3078. set dieleData ""
  3079. set ellData ""
  3080. set triData ""
  3081. set polyData ""
  3082. set gndData ""
  3083. set recTags ""
  3084. set cirTags ""
  3085. set dieleTags ""
  3086. set ellTags ""
  3087. set triTags ""
  3088. set polyTags ""
  3089. set gndTags ""
  3090. set pData ""
  3091. set pcal ""
  3092. set maxXcoord 879.00000
  3093. set maxYcoord 586.00000
  3094. if { $flag == 1 } {
  3095. set paletteXsize 0
  3096. set paletteYsize 0
  3097. set pbottomleftX 0
  3098. set pbottomleftY 0
  3099. set palFlag -1
  3100. set Xscale 0
  3101. set Yscale 0
  3102. }
  3103. set Nh 1024
  3104. set Nit 40
  3105. set J 6
  3106. set Nwx 8
  3107. set Nwy 10
  3108. set Nws 5
  3109. set Np 0.0
  3110. set Eps 1.0e-5
  3111. set matr 2
  3112. set od 5
  3113. set maxga 0
  3114. bind .c <Button-1> { }
  3115. bind .c <B1-Motion> { }
  3116. bind .c <ButtonRelease-1> { }
  3117. bind .c <Motion> { }
  3118. }
  3119. proc main { argc argv } {
  3120. global myAppFileName
  3121. global_init
  3122. if { $argc == 1 } {
  3123. set myAppFileName [lindex $argv 0]
  3124. puts "file: $myAppFileName.dat"
  3125. myAppFileOpen $myAppFileName.dat
  3126. }
  3127. }
  3128. main $argc $argv