TaskWindow.cpp 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942
  1. // workspace2.cpp : implementation of the CWorkSpaceBar2 class
  2. //
  3. #include "stdafx.h"
  4. #include "VisionPlus.h"
  5. #include "TaskWindow.h"
  6. #include "ToolWindow.h"
  7. #include "MainFrm.h"
  8. #include "GlobalSetting.h"
  9. #include "Utility.h"
  10. #include "ToolRenameDlg.h"
  11. #include "NodeWatchDlg.h"
  12. #include "Preferences.h"
  13. #include "TaskSettings.h"
  14. #include "Draw\DialogLink.h"
  15. #include "Draw\DialogLink.h"
  16. #include "HWindow.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. const int nBorderSize = 1;
  23. #define HTBUTTON_CUSTOM_1 HTHELP + 12
  24. #define HTBUTTON_CUSTOM_2 HTHELP + 13
  25. #define HTBUTTON_CUSTOM_3 HTHELP + 14
  26. // 绘制相关的参数
  27. #define COLOR_BLUE RGB(0,0,255)
  28. #define COLOR_BLUE_TEST RGB(255,0,0)
  29. #define LINK_WIDTH 1
  30. #define LINK_WIDTH_BOLD 3
  31. #define ARROW_LENGTH 5 // 箭头长度
  32. extern UINT Process(LPVOID lpParam);
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CWorkSpaceBar2
  35. IMPLEMENT_DYNAMIC(CTaskWindow, CBCGPStatic)
  36. BEGIN_MESSAGE_MAP(CTaskWindow, CBCGPStatic)
  37. ON_WM_CREATE()
  38. ON_WM_SIZE()
  39. ON_WM_PAINT()
  40. ON_WM_LBUTTONDOWN()
  41. ON_WM_CONTEXTMENU()
  42. ON_WM_SETFOCUS()
  43. ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_IN, OnUpdate)
  44. ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_OUT, OnUpdate)
  45. ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_NULL, OnUpdate)
  46. ON_UPDATE_COMMAND_UI(IDC_DRAW_SETTINGS, OnUpdate)
  47. ON_UPDATE_COMMAND_UI(IDC_DRAW_SNAP_TO_GRID, OnUpdate)
  48. ON_UPDATE_COMMAND_UI(IDC_DRAW_LEFT_ALIGN, OnUpdate)
  49. ON_UPDATE_COMMAND_UI(IDC_DRAW_RIGHT_ALIGN, OnUpdate)
  50. ON_UPDATE_COMMAND_UI(IDC_DRAW_TOP_ALIGN, OnUpdate)
  51. ON_UPDATE_COMMAND_UI(IDC_DRAW_BOTTOM_ALIGN, OnUpdate)
  52. ON_UPDATE_COMMAND_UI(IDC_DRAW_UP, OnUpdate)
  53. ON_UPDATE_COMMAND_UI(IDC_DRAW_FRONT, OnUpdate)
  54. ON_UPDATE_COMMAND_UI(IDC_DRAW_DOWN, OnUpdate)
  55. ON_UPDATE_COMMAND_UI(IDC_DRAW_BOTTOM, OnUpdate)
  56. ON_UPDATE_COMMAND_UI(IDC_DRAW_MAKE_SAME_SIZE, OnUpdate)
  57. ON_UPDATE_COMMAND_UI(IDC_DRAW_DELETE, OnUpdate)
  58. ON_UPDATE_COMMAND_UI(IDC_TASK_SETTING, OnUpdate)
  59. ON_UPDATE_COMMAND_UI(IDC_TASK_RUNONCE, OnUpdate)
  60. ON_BN_CLICKED(IDC_DRAW_UP, &CTaskWindow::OnBnClickedUp)
  61. ON_BN_CLICKED(IDC_DRAW_DOWN, &CTaskWindow::OnBnClickedDown)
  62. ON_BN_CLICKED(IDC_DRAW_FRONT, &CTaskWindow::OnBnClickedFront)
  63. ON_BN_CLICKED(IDC_DRAW_BOTTOM, &CTaskWindow::OnBnClickedBottom)
  64. ON_BN_CLICKED(IDC_DRAW_LEFT_ALIGN, &CTaskWindow::OnBnClickedLeftAlign)
  65. ON_BN_CLICKED(IDC_DRAW_RIGHT_ALIGN, &CTaskWindow::OnBnClickedRightAlign)
  66. ON_BN_CLICKED(IDC_DRAW_TOP_ALIGN, &CTaskWindow::OnBnClickedTopAlign)
  67. ON_BN_CLICKED(IDC_DRAW_BOTTOM_ALIGN, &CTaskWindow::OnBnClickedBottomAlign)
  68. ON_BN_CLICKED(IDC_DRAW_ZOOM_IN, &CTaskWindow::OnBnClickedZoomIn)
  69. ON_BN_CLICKED(IDC_DRAW_ZOOM_OUT, &CTaskWindow::OnBnClickedZoomOut)
  70. ON_BN_CLICKED(IDC_DRAW_ZOOM_NULL, &CTaskWindow::OnBnClickedZoomZero)
  71. ON_BN_CLICKED(IDC_TASK_SETTING, &CTaskWindow::OnBnClickedSettings)
  72. ON_BN_CLICKED(IDC_TASK_RUNONCE, &CTaskWindow::OnBnClickedRunOnce)
  73. END_MESSAGE_MAP()
  74. // void CTaskWindow::OnDraw(CDC* pDC)
  75. // {
  76. // CDocument* pDoc = GetDocument();
  77. // // TODO: 在此添加绘制代码
  78. // }
  79. // CTakView 诊断
  80. #ifdef _DEBUG
  81. void CTaskWindow::AssertValid() const
  82. {
  83. CBCGPStatic::AssertValid();
  84. }
  85. #ifndef _WIN32_WCE
  86. void CTaskWindow::Dump(CDumpContext& dc) const
  87. {
  88. CBCGPStatic::Dump(dc);
  89. }
  90. #endif
  91. #endif //_DEBUG
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CWorkSpaceBar2 construction/destruction
  94. CTaskWindow::CTaskWindow()
  95. {
  96. g_VatTypeMap.InitVarTypeMap();
  97. m_penLink.CreatePen(PS_SOLID, LINK_WIDTH, COLOR_BLUE);
  98. m_penLinkBold.CreatePen(PS_SOLID, LINK_WIDTH_BOLD, COLOR_BLUE);
  99. m_penLinkTest.CreatePen(PS_SOLID, LINK_WIDTH, COLOR_BLUE_TEST);
  100. g_pToolManager = CToolManager::GetInstance();
  101. m_TaskMode = TASK_MODE::MAIN_TASK;
  102. // 第一个参数, TRUE,需要手动复位。
  103. //第二个参数,默认状态初始状态,true,有信号,false无信号
  104. //(ResetEvent()恢复为无信号,无信号时会挂起)
  105. //如果设置为FALSE,当一个线程等待到事件信号后系统会自动将事件状态复原为无信号状态
  106. m_hExecuteEven = CreateEventW(NULL, TRUE, FALSE, NULL);
  107. // m_hBusyEven = CreateEventW(NULL, FALSE, TRUE, NULL);// 初始为有信号状态
  108. m_hDoneEven = CreateEventW(NULL, TRUE, FALSE, NULL);// 需要ResetEvent(),初始为有信号状态
  109. m_Links.clear();
  110. m_RunningTime = 0;
  111. m_dRunningCount = 0;
  112. m_hThread = NULL;
  113. m_nIndex = DEFAULT_TASK_WINDOW;
  114. m_bExitThread = false;
  115. m_nSleepTime = 1;
  116. m_ToolTip = NULL;
  117. m_nMarginLeft = 0;
  118. m_nMarginTop = 0;
  119. m_nMarginBottom = 0;
  120. m_nMarginRight = 0;
  121. }
  122. CTaskWindow::~CTaskWindow()
  123. {
  124. // m_SelTools.clear();
  125. // m_Links.clear();
  126. // m_TsetLinks.clear();
  127. // m_wndTree.DestroyWindow();
  128. //为了使线程退出
  129. m_bExitThread = true;
  130. SetEvent(m_hExecuteEven);
  131. SetEvent(m_hDoneEven);
  132. //// 2019-3-23 释放选择的工具
  133. //for (unsigned int i = 0; i < m_SelTools.size(); i++)
  134. //{
  135. // // 调用Release
  136. // if (m_SelTools[i].hDllTool)
  137. // {
  138. // // 调用Release接口
  139. // typedef void(*RELEASE)();
  140. // RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE);
  141. // if (Release)
  142. // {
  143. // Release();
  144. // }
  145. // FreeLibrary(m_SelTools[i].hDllTool);
  146. // }
  147. //}
  148. for (size_t i = 0; i < m_SelTools.size(); i++)
  149. {
  150. RELEASE_BUFFER(m_SelTools.at(i).pDllPtr);
  151. FreeLibrary(m_SelTools[i].hDllTool);
  152. }
  153. m_SelTools.clear();
  154. RELEASE_HANDLE(m_hExecuteEven);
  155. // RELEASE_HANDLE(m_hBusyEven);
  156. RELEASE_HANDLE(m_hDoneEven);
  157. RELEASE_BUFFER(m_ToolTip);
  158. // 绘图清理
  159. m_Bitmap[0].DeleteObject();
  160. m_Bitmap[1].DeleteObject();
  161. m_Bitmap[2].DeleteObject();
  162. WatchClear();
  163. m_wndToolBar.DestroyWindow();
  164. }
  165. /////////////////////////////////////////////////////////////////////////////
  166. // CWorkSpaceBar2 message handlers
  167. int CTaskWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
  168. {
  169. if (CBCGPStatic::OnCreate(lpCreateStruct) == -1)
  170. return -1;
  171. CRect rectDummy;
  172. rectDummy.SetRectEmpty();
  173. // Create tree control:
  174. const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES |
  175. TVS_LINESATROOT | TVS_HASBUTTONS;
  176. // m_wndTree.m_bVisualManagerStyle = TRUE;
  177. //
  178. // if (!m_wndTree.Create(dwViewStyle, rectDummy, this, 1))
  179. // {
  180. // TRACE0("Failed to create workspace view\n");
  181. // return -1; // fail to create
  182. // }
  183. //CBCGPToolBar::AddToolBarForImageCollection(IDR_TASKFRAME, IDB_TASKTOOLS);
  184. // Create toolbar:
  185. m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  186. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
  187. CRect(1, 1, 1, 1), AFX_IDW_DIALOGBAR + 6 + m_nIndex);
  188. // 以上增加的数字 6 是在 3 个 MainFrm 中添加的ToolBarID (1-3),Draw中添加的ToolBar ID (4-5)
  189. // 如果不设置ID,会造成多个对象使用一个ID,异常现象为图标显示不正确
  190. //m_wndToolBar.SetControlVisualMode(this);
  191. m_wndToolBar.LoadToolBar(IDR_TASKFRAME, 0, 0, TRUE /* Locked bar */, 0, 0, IDB_TASKTOOLS);
  192. // m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
  193. // m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() &
  194. // ~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
  195. m_wndToolBar.SetOwner(this);
  196. // 所有命令都将通过此对话框而不是父框架进行路由:
  197. m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
  198. // 设置工具栏的名称
  199. m_wndToolBar.SetWindowText(m_strTaskName);
  200. GetClientRect(rectDummy);
  201. m_editor.Create(dwViewStyle, rectDummy, (CWnd*)this, NULL);
  202. //m_editor.SetVirtualSize(CSize(1800, 600));
  203. m_editor.SetModified(FALSE);
  204. m_editor.SetBackgroundColor(globalData.clrBarHilite);
  205. m_editor.SetSnapToGrid(FALSE);
  206. m_editor.SetRestraints(RESTRAINT_VIRTUAL);
  207. m_editor.ShowGrid(false);
  208. m_editor.GetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom);
  209. // 2018.10.16 更换了TaskWnd和TreeCtrl的绑定方式
  210. m_editor.m_pBindTaskWnd = this;
  211. m_Bitmap[0].LoadBitmap(IDB_BITMAP_INVALID);
  212. m_Bitmap[1].LoadBitmap(IDB_BITMAP_EERROR);
  213. m_Bitmap[2].LoadBitmap(IDB_BITMAP_OK);
  214. // Load caption icons:
  215. m_CaptionIcons.SetImageSize(CSize(24, 24));
  216. m_CaptionIcons.Load(IDR_CAPTION_ICONS);
  217. globalUtils.ScaleByDPI(m_CaptionIcons);
  218. m_ToolTip = new CCustomToolTipCtrl;
  219. m_ToolTip->CreateEx(this, TTS_ALWAYSTIP);
  220. m_ToolTip->Activate(TRUE);//使活跃
  221. CRect rect;
  222. m_editor.GetClientRect(&rect); //获取树控件的客户区矩形
  223. m_ToolTip->AddTool(CWnd::FromHandle(m_editor.m_hWnd), _T("我的树"));
  224. m_ToolTip->SetDelayTime(500);
  225. //
  226. m_hThread = AfxBeginThread(Process, this);
  227. ;
  228. //
  229. // // 2018.10.16 更换了TaskWnd和TreeCtrl的绑定方式
  230. //m_wndTree.m_pBindTaskWnd = this;
  231. return 0;
  232. }
  233. void CTaskWindow::OnSize(UINT nType, int cx, int cy)
  234. {
  235. CBCGPStatic::OnSize(nType, cx, cy);
  236. // Tree control should cover a whole client area:
  237. // m_wndTree.SetWindowPos(NULL, nBorderSize, nBorderSize,
  238. // cx - 2 * nBorderSize, cy - 2 * nBorderSize,
  239. // SWP_NOACTIVATE | SWP_NOZORDER);
  240. int nToobarHeidit = 25;
  241. if (m_wndToolBar.m_hWnd)
  242. {
  243. m_wndToolBar.SetWindowPos(NULL, 0, 0, cx, nToobarHeidit, SWP_NOACTIVATE | SWP_NOZORDER);
  244. }
  245. if (m_editor.m_hWnd)
  246. {
  247. m_editor.MoveWindow(0, nToobarHeidit, cx, cy - nToobarHeidit);
  248. m_editor.RedrawWindow();
  249. }
  250. }
  251. BOOL CTaskWindow::PreTranslateMessage(MSG* pMsg)
  252. {
  253. if (pMsg->message == WM_MOUSEMOVE)
  254. {
  255. CPoint pt = pMsg->pt;
  256. m_editor.ScreenToVirtual(pt);
  257. HTREEITEM item = m_editor.GetCursorItem();
  258. if (m_Item != item)
  259. {
  260. m_Item = item;
  261. if (item != NULL)
  262. {
  263. CString str;
  264. //TOOL_INTERFACE* pInf = this->GetInterfaceByHandle(item);
  265. TOOL* pTool = this->GetToolByHandle(item);
  266. if (pTool != NULL)
  267. {
  268. CString strName;
  269. CString strShowName;
  270. CString strAliasName;
  271. CString strStatus;
  272. CString strInfo;
  273. CString strEven;
  274. TOOL* pActiveTool = GetToolByHandle(item);
  275. if (pActiveTool != NULL && TOOL_ERROR == pActiveTool->nToolState)
  276. {
  277. strStatus = _T("工具状态:初始化错误!");
  278. }
  279. if (pActiveTool != NULL && TOOL_SUCCESS == pActiveTool->nToolState)
  280. {
  281. if (RT_ERROR == pActiveTool->nExecCode)
  282. {
  283. strStatus = _T("工具状态: 执行错误!");
  284. }
  285. else if (RT_TIMEOUT == pActiveTool->nExecCode)
  286. {
  287. strStatus = _T("工具状态: 执行超时!");
  288. }
  289. else if (RT_NONE == pActiveTool->nExecCode)
  290. {
  291. strStatus = _T("工具状态: 未执行!");
  292. }
  293. else if (RT_SUCCESS == pActiveTool->nExecCode)
  294. {
  295. strStatus = _T("工具状态: 执行正确!");
  296. }
  297. else if (RT_GOTO == pActiveTool->nExecCode)
  298. {
  299. strStatus = _T("工具状态: 执行跳转!");
  300. }
  301. else
  302. {
  303. strStatus = _T("工具状态: 未知状态!");
  304. }
  305. }
  306. CString strInSleep;
  307. if (pActiveTool->nInSleep > 0)
  308. {
  309. strInSleep.Format(_T("入口延时: %d ms\n"), pActiveTool->nInSleep);
  310. }
  311. CString strOutSleep;
  312. if (pActiveTool->nOutSleep > 0)
  313. {
  314. strOutSleep.Format(_T("出口延时: %d ms\n"), pActiveTool->nOutSleep);
  315. }
  316. if (pActiveTool->pDllPtr->m_Even.hEvenHandle != NULL)
  317. {
  318. strEven.Format(_T("触发模式: Even\n"));
  319. }
  320. strName.Format(_T("工具名称: %s \n"), pActiveTool->strName);
  321. strAliasName.Format(_T("工具别名: %s \n"), pActiveTool->strAliasName);
  322. strShowName.Format(_T("显示名称: %s \n"), pActiveTool->strShowName);
  323. strInfo.Format(_T("工具信息: %s \n"), pActiveTool->strInfo);
  324. str.Format(_T("%s%s%s%s%s%s%s%s"), strName, strAliasName, strShowName, strInSleep, strOutSleep, strEven, strInfo, strStatus);
  325. m_ToolTip->m_InterfaceDispType = INTERFACE_DISP_TYPE::IVDT_CSTRING;
  326. }
  327. else
  328. {
  329. m_ToolTip->m_hvObj.Clear();
  330. m_ToolTip->m_Image.Clear();
  331. //ClearWindow(m_ToolTip->m_HTWindow);
  332. CString strProtName;
  333. CString strProtType;
  334. CString strProtInfo;
  335. CString strProtVilue;
  336. TOOL_INTERFACE* pInf = GetInterfaceByHandle(item);
  337. if (pInf != NULL)
  338. {
  339. CString strValue;
  340. m_ToolTip->m_InterfaceDispType = UpdateUIValue(strValue, &m_ToolTip->m_Image, &m_ToolTip->m_hvObj, pInf);
  341. if (strValue.IsEmpty())
  342. {
  343. strValue = _T("NULL");
  344. }
  345. strProtName.Format(_T("ProtName: [ %s ]\n"), pInf->strName);
  346. strProtType.Format(_T("ProtType : [ %s ]\n"), g_VatTypeMap.GetVarTypeName(pInf->VarType));
  347. strProtInfo.Format(_T("ProtInfo : [ %s ]\n"), pInf->strInfo);
  348. strProtVilue.Format(_T(" __Vilue : [ %s ]"), strValue);
  349. }
  350. str.Format(_T("%s%s%s%s"), strProtName, strProtType, strProtInfo, strProtVilue);
  351. if (str.IsEmpty())
  352. {
  353. str = _T("NULL");
  354. }
  355. }
  356. m_ToolTip->UpdateTipText(str, CWnd::FromHandle(m_editor.m_hWnd));
  357. m_ToolTip->RelayEvent(pMsg);
  358. }
  359. }
  360. }
  361. if (pMsg->message == WM_KEYDOWN)
  362. {
  363. if (GetKeyState(VK_CONTROL) & 0x80)
  364. if (pMsg->wParam == 'c' || pMsg->wParam == 'C')
  365. {
  366. OnBnClickedButtonCopy();
  367. }
  368. if (pMsg->wParam == 'v' || pMsg->wParam == 'V')
  369. {
  370. OnBnClickedButtonPaste();
  371. }
  372. }
  373. return CBCGPStatic::PreTranslateMessage(pMsg);
  374. }
  375. void CTaskWindow::OnPaint()
  376. {
  377. CPaintDC dc(this); // device context for painting
  378. CRect rectTree;
  379. // m_wndTree.GetWindowRect(rectTree);
  380. // ScreenToClient(rectTree);
  381. //
  382. // rectTree.InflateRect(nBorderSize, nBorderSize);
  383. //
  384. GetClientRect(rectTree);
  385. dc.Draw3dRect(rectTree, globalData.clrBarShadow, globalData.clrBarShadow);
  386. // m_wndTree.SetBkColor(globalData.clrBarHilite);
  387. }
  388. ///////////////////////////////////////////////////
  389. // 从工具箱中添加新的工具到任务栏
  390. void CTaskWindow::AddNewTools(CString strToolName, HTREEITEM hPrevItem)
  391. {
  392. // 处理重名问题
  393. CString strToolShowName = strToolName;
  394. // // 遍历所有节点,查找是否有重名节点,并且找一下序号
  395. int nRepeat = 1;
  396. vector<CString> ShowNameLink;
  397. for (int i = 0; i < m_SelTools.size(); i++)
  398. {
  399. CString strName = m_SelTools[i].strName;
  400. CString strShow = m_SelTools[i].strShowName;
  401. if (strName.Find(strToolName) >= 0)
  402. {
  403. nRepeat++;
  404. ShowNameLink.push_back(strShow);
  405. }
  406. }
  407. // 生成界面中的名字
  408. if (nRepeat > 0)
  409. {
  410. strToolShowName.AppendFormat(_T(" %d"), nRepeat);
  411. int xxx = 0;
  412. for (int j = 0; j < ShowNameLink.size(); j++)
  413. {
  414. if (strToolShowName.Compare(ShowNameLink[j]) == 0)
  415. {
  416. xxx++;
  417. strToolShowName.AppendFormat(_T("-%d"), xxx);
  418. }
  419. }
  420. //strToolShowName.AppendFormat(_T(" %d"), nRepeat+1 );
  421. m_RenameList.insert(pair<CString, CString>(strToolShowName, strToolName));
  422. }
  423. // 依次将对应的工具信息添加到界面中
  424. for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++)
  425. {
  426. TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i];
  427. // 如果拖拽过来的是一个分类,则不处理
  428. if (cate.strName.Compare(strToolName) == 0)
  429. {
  430. return;
  431. }
  432. // 遍历本分类中的所有信息
  433. for (unsigned int j = 0; j < cate.Tools.size(); j++)
  434. {
  435. TOOL& tool = cate.Tools[j];
  436. // 如果找到了对应的工具
  437. if (tool.strName.Compare(strToolName) == 0 ||
  438. tool.strAliasName.Compare(strToolName) == 0
  439. )
  440. {
  441. // 则把本工具,以及下面的所有接口,都添加到界面中
  442. tool.strShowName = strToolShowName;
  443. CFunctionBlock* obj = new CFunctionBlock(tool, m_nIndex);
  444. CString strTitle;
  445. strTitle.Format(_T("%d"), m_SelTools.size());
  446. obj->SetTitle(strTitle);
  447. m_editor.StartDrawingObject(obj);
  448. this->UpdateTools();
  449. }
  450. }
  451. }
  452. CString str;
  453. str.Format(_T("Task[%d] Add:%s"), m_nIndex, strToolShowName);
  454. USES_CONVERSION;
  455. char * s_str = T2A(str);
  456. g_Logger.Info(0, __FILE__, __LINE__, s_str);;
  457. }
  458. ////////////////////////////////////////////////////////////////////
  459. // 从工具箱中添加新的工具到任务栏(用于反序列化使用)
  460. BOOL CTaskWindow::AddNewTools(const TOOL& newTool)
  461. {
  462. CDiagramEntityContainer* pContainer = m_editor.GetDiagramEntityContainer();
  463. // 如果两个名字不同,则需要加到重命名列表中
  464. if (newTool.strShowName.Compare(newTool.strName) != 0)
  465. {
  466. m_RenameList.insert(pair<CString, CString>(newTool.strShowName, newTool.strName));
  467. }
  468. // 依次将对应的工具信息添加到界面中
  469. for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++)
  470. {
  471. TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i];
  472. // 遍历本分类中的所有信息
  473. for (unsigned int j = 0; j < cate.Tools.size(); j++)
  474. {
  475. TOOL tool = cate.Tools[j];
  476. // 如果找到了对应的工具
  477. if (tool.strName.Compare(newTool.strName) == 0 ||
  478. tool.strAliasName.Compare(newTool.strName) == 0
  479. )
  480. {
  481. for (int k = 0; k < tool.Interfaces.size(); k++)
  482. {
  483. // 此处添加的判断,是为了应对工具端口的增加。
  484. if (k < newTool.Interfaces.size())
  485. {
  486. if (tool.Interfaces[k].VarType == (newTool.Interfaces[k].VarType))
  487. {
  488. bool bShow = newTool.Interfaces[k].bShow;
  489. tool.Interfaces[k].bShow = bShow;
  490. tool.Interfaces[k].nUseCount = newTool.Interfaces[k].nUseCount;
  491. }
  492. }
  493. }
  494. // 则把本工具,以及下面的所有接口,都添加到界面中
  495. CFunctionBlock* obj;
  496. obj = new CFunctionBlock(tool, m_nIndex);
  497. CString strTitle;
  498. strTitle.Format(_T("--%d"), m_SelTools.size());
  499. obj->SetTitle(strTitle);
  500. // 在此添加其它属性
  501. obj->Tools.strShowName = newTool.strShowName;
  502. obj->Tools.rect = newTool.rect;
  503. obj->Tools.strLinkName = newTool.strLinkName;
  504. obj->Tools.nInSleep = newTool.nInSleep;
  505. obj->Tools.nOutSleep = newTool.nOutSleep;
  506. obj->Tools.strInfo = newTool.strInfo;
  507. obj->Tools.nUseCount = newTool.nUseCount;
  508. obj->SetRect(newTool.rect);
  509. pContainer->Add(obj);
  510. return TRUE;
  511. }
  512. }
  513. }
  514. return FALSE;
  515. }
  516. ////////////////////////////////////////////////////////////////////
  517. // 从工具箱中添加新的工具到任务栏
  518. BOOL CTaskWindow::AddNewTools2(const TOOL& newTool, CString* p_strShowName)
  519. {
  520. CDiagramEntityContainer* pContainer = m_editor.GetDiagramEntityContainer();
  521. CString strToolName = newTool.strShowName;
  522. // 处理重名问题
  523. CString strToolShowName = strToolName;
  524. // // 遍历所有节点,查找是否有重名节点,并且找一下序号
  525. int nRepeat = 1;
  526. vector<CString> ShowNameLink;
  527. for (int i = 0; i < m_SelTools.size(); i++)
  528. {
  529. CString strName = m_SelTools[i].strName;
  530. CString strShow = m_SelTools[i].strShowName;
  531. if (strName.Find(strToolName) >= 0)
  532. {
  533. nRepeat++;
  534. ShowNameLink.push_back(strShow);
  535. }
  536. }
  537. // 生成界面中的名字
  538. if (nRepeat > 0)
  539. {
  540. strToolShowName.AppendFormat(_T(" %d"), nRepeat);
  541. int xxx = 0;
  542. for (int j = 0; j < ShowNameLink.size(); j++)
  543. {
  544. if (strToolShowName.Compare(ShowNameLink[j]) == 0)
  545. {
  546. xxx++;
  547. strToolShowName.AppendFormat(_T("-%d"), xxx);
  548. }
  549. }
  550. //strToolShowName.AppendFormat(_T(" %d"), nRepeat+1 );
  551. m_RenameList.insert(pair<CString, CString>(strToolShowName, strToolName));
  552. }
  553. *p_strShowName = strToolShowName;
  554. // 依次将对应的工具信息添加到界面中
  555. for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++)
  556. {
  557. TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i];
  558. // 遍历本分类中的所有信息
  559. for (unsigned int j = 0; j < cate.Tools.size(); j++)
  560. {
  561. TOOL tool = cate.Tools[j];
  562. // 如果找到了对应的工具
  563. if (tool.strName.Compare(newTool.strName) == 0 ||
  564. tool.strAliasName.Compare(newTool.strName) == 0
  565. )
  566. {
  567. // 把本工具,以及下面的所有接口,都添加到界面中
  568. CFunctionBlock* obj;
  569. obj = new CFunctionBlock(tool, m_nIndex);
  570. CString strTitle;
  571. strTitle.Format(_T("--%d"), m_SelTools.size());
  572. obj->SetTitle(strTitle);
  573. // 在此添加其它属性
  574. obj->Tools.strShowName = strToolShowName;
  575. obj->Tools.rect = newTool.rect;
  576. obj->Tools.strLinkName = tool.strLinkName;
  577. obj->Tools.nInSleep = tool.nInSleep;
  578. obj->Tools.nOutSleep = tool.nOutSleep;
  579. obj->Tools.strInfo = tool.strInfo;
  580. obj->Tools.nUseCount = tool.nUseCount;
  581. obj->SetRect(newTool.rect);
  582. pContainer->Add(obj);
  583. return TRUE;
  584. }
  585. }
  586. }
  587. return FALSE;
  588. }
  589. ////////////////////////////////////////////////////////////////////
  590. // 根据用户拖动的内容添加接口连线
  591. BOOL CTaskWindow::AddLink(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD)
  592. {
  593. TOOL_INTERFACE* pInfStart = NULL;
  594. TOOL_INTERFACE* pInfEnd = NULL;
  595. // 首先搜索到起点和终点
  596. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  597. {
  598. TOOL& tool = m_SelTools[i];
  599. for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
  600. {
  601. TOOL_INTERFACE inf = tool.Interfaces[j];
  602. if (inf.hHandle == m_hItemDragS)
  603. {
  604. pInfStart = &tool.Interfaces[j];
  605. pInfStart->nUseCount++;
  606. break;
  607. }
  608. else if (inf.hHandle == m_hItemDragD)
  609. {
  610. pInfEnd = &tool.Interfaces[j];
  611. pInfEnd->nUseCount++;
  612. break;
  613. }
  614. }
  615. }
  616. if (pInfStart == NULL || pInfEnd == NULL)
  617. {
  618. return FALSE;
  619. }
  620. // 建立关联
  621. MakeLink(*pInfStart, *pInfEnd);
  622. return TRUE;
  623. }
  624. ////////////////////////////////////////////////////////////////////
  625. // 根据用户拖动的内容添加接口连线
  626. BOOL CTaskWindow::AddLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest, bool bIsLoad)
  627. {
  628. TOOL_INTERFACE* pInfStart = NULL;
  629. TOOL_INTERFACE* pInfEnd = NULL;
  630. // 首先搜索到起点和终点
  631. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  632. {
  633. TOOL& tool = m_SelTools[i];
  634. for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
  635. {
  636. TOOL_INTERFACE inf = tool.Interfaces[j];
  637. if (inf == source/* && inf.InfDirection == INF_DIRECTION::INF_OUT && inf.strParentName != dest.strParentName*/)
  638. {
  639. pInfStart = &tool.Interfaces[source.nIndex - 1];
  640. if (!bIsLoad)
  641. pInfStart->nUseCount++;
  642. //break;
  643. }
  644. if (inf == dest /* && inf.InfDirection == INF_DIRECTION::INF_IN && inf.strParentName != source.strParentName*/)
  645. {
  646. pInfEnd = &tool.Interfaces[dest.nIndex - 1];
  647. if (!bIsLoad)
  648. pInfEnd->nUseCount++;
  649. //break;
  650. }
  651. }
  652. }
  653. if (pInfStart == NULL || pInfEnd == NULL)
  654. {
  655. if (pInfStart == NULL)
  656. {
  657. CString strMsg;
  658. strMsg.Format(_T("Task[%d] 找不到 %s.%s "),m_nIndex, source.strParentName, source.strName);
  659. USES_CONVERSION;
  660. char * s_str = T2A(strMsg);
  661. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  662. }
  663. if (pInfEnd == NULL)
  664. {
  665. CString strMsg;
  666. strMsg.Format(_T("Task[%d] 找不到 %s.%s "),m_nIndex, dest.strParentName, dest.strName);
  667. USES_CONVERSION;
  668. char * s_str = T2A(strMsg);
  669. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  670. }
  671. CString strMsg;
  672. strMsg.Format(_T("Task[%d] Make link Error: %s-%s to %s-%s"),m_nIndex,
  673. source.strParentName, source.strName,
  674. dest.strParentName, dest.strName);
  675. USES_CONVERSION;
  676. char * s_str = T2A(strMsg);
  677. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  678. return FALSE;
  679. }
  680. if (pInfStart->strParentName == pInfEnd->strParentName)
  681. {
  682. return FALSE;
  683. }
  684. BOOL status = MakeLink(*pInfStart, *pInfEnd);// 建立关联
  685. return status;
  686. return TRUE;
  687. }
  688. ///////////////////////////////////////////////////////////////////////////
  689. // 根据用户拖动的内容添加接口连线
  690. BOOL CTaskWindow::AddTestLink(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD)
  691. {
  692. TOOL_INTERFACE* pInfStart = NULL;
  693. TOOL_INTERFACE* pInfEnd = NULL;
  694. // 首先搜索到起点和终点
  695. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  696. {
  697. TOOL& tool = m_SelTools[i];
  698. for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
  699. {
  700. TOOL_INTERFACE inf = tool.Interfaces[j];
  701. if (inf.hHandle == m_hItemDragS)
  702. {
  703. pInfStart = &tool.Interfaces[j];
  704. break;
  705. }
  706. else if (inf.hHandle == m_hItemDragD)
  707. {
  708. pInfEnd = &tool.Interfaces[j];
  709. break;
  710. }
  711. }
  712. }
  713. if (pInfStart == NULL || pInfEnd == NULL)
  714. {
  715. return FALSE;
  716. }
  717. // 建立关联
  718. MakeTestLink(*pInfStart, *pInfEnd);
  719. return TRUE;
  720. }
  721. ///////////////////////////////////////////////////////////////////////////
  722. // 添加工具到任务栏的时候智能链接
  723. void CTaskWindow::SmartLink()
  724. {
  725. int nIndex = (int)m_SelTools.size() - 1;
  726. if (nIndex < 1)
  727. {
  728. return;
  729. }
  730. //获取最后一个添加的工具
  731. TOOL tool = m_SelTools[nIndex];
  732. for (unsigned int i = 0; i < tool.Interfaces.size(); i++)
  733. {
  734. const TOOL_INTERFACE& DestInf = tool.Interfaces[i];
  735. // 如果当前接口设置了不显示,则不显示该接口
  736. if ((DestInf.InfType == INF_VALUE_1 || DestInf.InfType == INF_VALUE_2 || DestInf.InfType == INF_VALUE_3 || DestInf.InfType == INF_VALUE_4)
  737. && (DestInf.InfDirection == INF_IN))
  738. {
  739. if (DestInf.bSmartLink && DestInf.bShow)
  740. {
  741. ToSmartLink(DestInf);
  742. }
  743. }
  744. }
  745. }
  746. ///////////////////////////////////////////////////////////////////////////
  747. //通过输入的目标端口执行智能链接动作
  748. void CTaskWindow::ToSmartLink(const TOOL_INTERFACE& DestInf)
  749. {
  750. //遍历现有工具(逆序),找最近的端口链接
  751. //遍历的时候跳过了工具自身,所以下面下面的初始值为 2
  752. for (int j = (int)m_SelTools.size() - 2; j >= 0; j--)
  753. {
  754. TOOL toolTemp = m_SelTools[j];
  755. //目前执行的智能链接策略为,逆序找最近的同属性端口,可能不是客户最终需要的端口,所以需要优化
  756. for (unsigned int k = 0; k < toolTemp.Interfaces.size(); k++)
  757. {
  758. const TOOL_INTERFACE& SourceInf = toolTemp.Interfaces[k];
  759. if ((SourceInf.InfType == INF_VALUE_1 || SourceInf.InfType == INF_VALUE_2 || SourceInf.InfType == INF_VALUE_3 || SourceInf.InfType == INF_VALUE_4)
  760. && (SourceInf.InfDirection == INF_OUT))
  761. {
  762. if (DestInf.VarType == SourceInf.VarType)
  763. {
  764. if (DestInf.bSmartLink && SourceInf.bSmartLink)
  765. {
  766. AddLink(SourceInf, DestInf);
  767. return;
  768. }
  769. }
  770. }
  771. }
  772. }
  773. }
  774. //
  775. ///////////////////////////////////////////////////////////////
  776. //// 判断一个节点是否是输入节点
  777. //BOOL CTaskWindow::IsInputNode(const HTREEITEM& handle)
  778. //{
  779. // TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle);
  780. // if (pInf == NULL)
  781. // {
  782. // return FALSE;
  783. // }
  784. // ASSERT(pInf != NULL);
  785. //
  786. // if (pInf->bWay == INF_IN)
  787. // {
  788. // return TRUE;
  789. // }
  790. // else
  791. // {
  792. // return FALSE;
  793. // }
  794. //}
  795. //
  796. ///////////////////////////////////////////////////////////////
  797. //// 判断一个节点是否是输出节点
  798. //BOOL CTaskWindow::IsOutputNode(const HTREEITEM& handle)
  799. //{
  800. // TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle);
  801. // if (pInf == NULL)
  802. // {
  803. // return FALSE;
  804. // }
  805. // ASSERT(pInf != NULL);
  806. //
  807. // if (pInf->bWay == INF_OUT)
  808. // {
  809. // return TRUE;
  810. // }
  811. // else
  812. // {
  813. // return FALSE;
  814. // }
  815. //}
  816. //////////////////////////////////////////////////////////////////
  817. // 计算连线的绘制坐标
  818. LINK_POINTS CTaskWindow::CalcLinkPoints(const LINK& lnk)
  819. {
  820. LINK_POINTS lp;
  821. TOOL_INTERFACE toolStart = lnk.source;
  822. TOOL_INTERFACE toolEnd = lnk.dest;
  823. // 根据对应的矩形区域进行绘制
  824. CRect rcStart, rcEnd;
  825. TOOL_INTERFACE* pInfStart = GetInterfaceByHandle(toolStart.hHandle);
  826. TOOL_INTERFACE* pInfEnd = GetInterfaceByHandle(toolEnd.hHandle);
  827. if (pInfStart && pInfEnd)
  828. {
  829. rcStart = pInfStart->rect;
  830. rcEnd = pInfEnd->rect;
  831. }
  832. // TRACE(_T("Start: %d %d %d %d - rcEnd: %d %d %d %d\n"),
  833. // /*m_wndTree.GetItemText(toolStart.hHandle), m_wndTree.GetItemText(toolEnd.hHandle),*/
  834. // rcStart.left, rcStart.top, rcStart.right, rcStart.bottom,
  835. // rcEnd.left, rcEnd.top, rcEnd.right, rcEnd.bottom);
  836. lp.ptStart.x = rcStart.right;
  837. lp.ptStart.y = rcStart.top + rcStart.Height() / 2;
  838. lp.ptEnd.x = rcEnd.right;
  839. lp.ptEnd.y = rcEnd.top + rcEnd.Height() / 2;
  840. lp.ptEnd.x = lp.ptEnd.x - PORT_WIDTH;
  841. if ((lp.ptStart.x < lp.ptEnd.x) && (lp.ptStart.y == lp.ptEnd.y))//1
  842. lp.nMode = 1;
  843. else if ((lp.ptStart.x >= lp.ptEnd.x) && (lp.ptStart.y == lp.ptEnd.y))//2
  844. lp.nMode = 2;
  845. else if ((lp.ptStart.x <= lp.ptEnd.x) && (lp.ptStart.y >= lp.ptEnd.y))//3
  846. lp.nMode = 3;
  847. else if ((lp.ptStart.x < lp.ptEnd.x) && (lp.ptStart.y < lp.ptEnd.y))//4
  848. lp.nMode = 4;
  849. else if ((lp.ptStart.x >= lp.ptEnd.x) && (lp.ptStart.y <= lp.ptEnd.y))//5
  850. lp.nMode = 5;
  851. else if ((lp.ptStart.y > lp.ptEnd.y) && (lp.ptStart.x > lp.ptEnd.x))//6
  852. lp.nMode = 6;
  853. switch (lp.nMode)
  854. {
  855. case 1:
  856. {
  857. lp.ptCorner1 = lp.ptStart;
  858. lp.ptCorner2 = lp.ptStart;
  859. lp.ptCorner3 = lp.ptEnd;
  860. lp.ptCorner4 = lp.ptEnd;
  861. }
  862. break;
  863. case 2:
  864. {
  865. lp.ptCorner1.x = lp.ptStart.x + 10;
  866. lp.ptCorner1.y = lp.ptStart.y;
  867. lp.ptCorner4.x = lp.ptEnd.x - 10;
  868. lp.ptCorner4.y = lp.ptEnd.y;
  869. lp.ptCorner2.x = lp.ptCorner1.x;
  870. lp.ptCorner2.y = lp.ptCorner1.y + 10;
  871. lp.ptCorner3.x = lp.ptCorner4.x;
  872. lp.ptCorner3.y = lp.ptCorner2.y;
  873. }
  874. break;
  875. case 3:
  876. case 4:
  877. {
  878. lp.ptCorner1.x = (long)((lp.ptEnd.x - lp.ptStart.x) * 0.1) + lp.ptStart.x;
  879. lp.ptCorner1.y = (long)lp.ptStart.y;
  880. lp.ptCorner2.x = (long)lp.ptCorner1.x;
  881. lp.ptCorner2.y = lp.ptEnd.y;
  882. lp.ptCorner3 = lp.ptCorner2;
  883. lp.ptCorner4 = lp.ptCorner2;
  884. }
  885. break;
  886. case 5:
  887. {
  888. lp.ptCorner1.x = lp.ptStart.x + 10;
  889. lp.ptCorner1.y = lp.ptStart.y;
  890. lp.ptCorner4.x = lp.ptEnd.x - 10;
  891. lp.ptCorner4.y = lp.ptEnd.y;
  892. lp.ptCorner2.x = lp.ptCorner1.x;
  893. lp.ptCorner2.y = (long)((lp.ptCorner4.y - lp.ptCorner1.y) * 0.1) + lp.ptCorner1.y;
  894. lp.ptCorner3.x = lp.ptCorner4.x;
  895. lp.ptCorner3.y = lp.ptCorner2.y;
  896. }
  897. break;
  898. case 6:
  899. {
  900. lp.ptCorner1.x = lp.ptStart.x + 10;
  901. lp.ptCorner1.y = lp.ptStart.y;
  902. lp.ptCorner4.x = lp.ptEnd.x - 10;
  903. lp.ptCorner4.y = lp.ptEnd.y;
  904. lp.ptCorner2.x = lp.ptCorner1.x;
  905. lp.ptCorner2.y = (long)((lp.ptCorner1.y - lp.ptCorner4.y) * 0.1) + lp.ptCorner4.y;
  906. lp.ptCorner3.x = lp.ptCorner4.x;
  907. lp.ptCorner3.y = lp.ptCorner2.y;
  908. }
  909. break;
  910. default:
  911. break;
  912. }
  913. return lp;
  914. }
  915. ////////////////////////////////////////////////////////////
  916. // 绘制链接
  917. void CTaskWindow::DrawLink(CDC* pDC)
  918. {
  919. if (m_Links.size() <= 0)
  920. {
  921. return;
  922. }
  923. LINK_MAP::iterator iter;
  924. for (iter = m_Links.begin(); iter != m_Links.end(); iter++)
  925. {
  926. // 计算需要绘制link的联线坐标位置
  927. LINK_POINTS lps = CalcLinkPoints(*iter);
  928. // 选择画笔
  929. CPen *pOldPen = NULL;
  930. // 根据线条的命中与否选择不同的画笔
  931. if (iter->bShow)
  932. {
  933. if (iter->bActive)
  934. {
  935. pOldPen = pDC->SelectObject(&m_penLinkBold);
  936. }
  937. else
  938. {
  939. pOldPen = pDC->SelectObject(&m_penLink);
  940. }
  941. pDC->MoveTo(lps.ptStart);
  942. pDC->LineTo(lps.ptCorner1);
  943. pDC->LineTo(lps.ptCorner2);
  944. pDC->LineTo(lps.ptCorner3);
  945. pDC->LineTo(lps.ptCorner4);
  946. pDC->LineTo(lps.ptEnd);
  947. // 绘制箭头
  948. CPoint ptArrowTop, ptArrowBottom;
  949. ptArrowTop.x = lps.ptEnd.x - ARROW_LENGTH;
  950. ptArrowTop.y = lps.ptEnd.y + ARROW_LENGTH;
  951. ptArrowBottom.x = ptArrowTop.x;
  952. ptArrowBottom.y = lps.ptEnd.y - ARROW_LENGTH;
  953. pDC->LineTo(ptArrowTop);
  954. pDC->MoveTo(lps.ptEnd);
  955. pDC->LineTo(ptArrowBottom);
  956. pDC->SelectObject(pOldPen);
  957. }
  958. }
  959. }
  960. ////////////////////////////////////////////////////////////
  961. // 绘制预览链接
  962. void CTaskWindow::DrawPreviewLink(CDC* pDC)
  963. {
  964. if (m_TsetLinks.size() <= 0)
  965. {
  966. return;
  967. }
  968. LINK_MAP::iterator iter;
  969. for (iter = m_TsetLinks.begin(); iter != m_TsetLinks.end(); iter++)
  970. {
  971. LINK_POINTS lps = CalcLinkPoints(*iter);
  972. // 选择画笔
  973. CPen *pOldPen = NULL;
  974. pOldPen = pDC->SelectObject(&m_penLinkTest);
  975. pDC->MoveTo(lps.ptStart);
  976. pDC->LineTo(lps.ptCorner1);
  977. pDC->LineTo(lps.ptCorner2);
  978. pDC->LineTo(lps.ptCorner3);
  979. pDC->LineTo(lps.ptCorner4);
  980. pDC->LineTo(lps.ptEnd);
  981. // 绘制箭头
  982. CPoint ptArrowTop, ptArrowBottom;
  983. ptArrowTop.x = lps.ptEnd.x - ARROW_LENGTH;
  984. ptArrowTop.y = lps.ptEnd.y + ARROW_LENGTH;
  985. ptArrowBottom.x = ptArrowTop.x;
  986. ptArrowBottom.y = lps.ptEnd.y - ARROW_LENGTH;
  987. pDC->LineTo(ptArrowTop);
  988. pDC->MoveTo(lps.ptEnd);
  989. pDC->LineTo(ptArrowBottom);
  990. pDC->SelectObject(pOldPen);
  991. }
  992. }
  993. /////////////////////////////////////////////////////////////////////
  994. // 更新节点数据结构
  995. void CTaskWindow::UpdateTools(bool bIsLoad )
  996. {
  997. CDiagramEntityContainer* objs = static_cast<CDiagramEntityContainer*> (m_editor.GetDiagramEntityContainer());
  998. if (objs)
  999. {
  1000. UINT nIndex = 0;
  1001. for (UINT u = 0; u < objs->GetSize(); u++)
  1002. {
  1003. // if (objs->GetAt(u)->GetType() != _T("Tool"))
  1004. // {
  1005. // continue;
  1006. // }
  1007. CFunctionBlock* obj = (CFunctionBlock*)objs->GetAt(u);
  1008. CString strTitle;
  1009. strTitle.Format(_T("%d"), nIndex);
  1010. obj->Tools.nToolID = nIndex;
  1011. obj->SetTitle(strTitle);
  1012. CString strToolShowName = obj->Tools.strShowName;
  1013. BOOL bFind = FALSE;
  1014. UINT i = 0;
  1015. HTREEITEM hParent = obj->Tools.hHandle;
  1016. // 查找当前选中的工具集合中是否有当前的工具
  1017. for (; i < m_SelTools.size(); i++)
  1018. {
  1019. if (m_SelTools[i].strShowName.Compare(strToolShowName) == 0)
  1020. {
  1021. bFind = TRUE;
  1022. break;
  1023. }
  1024. }
  1025. // 如果找到了这个工具,只需要调整一下顺序,然后更新句柄
  1026. if (bFind)
  1027. {
  1028. if (i > nIndex)
  1029. {
  1030. TOOL toolTemp = m_SelTools[i];
  1031. m_SelTools[i] = m_SelTools[nIndex];
  1032. m_SelTools[nIndex] = toolTemp;
  1033. }
  1034. else if (i < nIndex)
  1035. {
  1036. hParent = obj->Tools.hHandle;
  1037. continue;
  1038. }
  1039. UpdateExistTool(m_SelTools[nIndex], obj->Tools);
  1040. //用来在页面上显示工具是否需要触发
  1041. TOOL tool = m_SelTools[nIndex];
  1042. EVEN m_hEven = tool.pDllPtr->m_Even;
  1043. obj->SetToolMode(m_hEven.hEvenHandle);
  1044. nIndex++;
  1045. }
  1046. // 否则是一个新的工具
  1047. else
  1048. {
  1049. UpdateNewTool(strToolShowName, obj->Tools, bIsLoad);
  1050. }
  1051. }
  1052. this->UpdateLink();
  1053. }
  1054. }
  1055. //////////////////////////////////////////////////////////////////
  1056. // 更新现有工具
  1057. void CTaskWindow::UpdateExistTool(TOOL& tool, TOOL& tool_Info)
  1058. {
  1059. // 获取句柄
  1060. tool.hHandle = tool_Info.hHandle;
  1061. tool.rect = tool_Info.rect;
  1062. tool.nToolID = tool_Info.nToolID;
  1063. tool_Info.nInSleep = tool.nInSleep;
  1064. tool_Info.nOutSleep = tool.nOutSleep;
  1065. tool_Info.strLinkName = tool.strLinkName;
  1066. for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
  1067. {
  1068. TOOL_INTERFACE& inf = tool.Interfaces[j];
  1069. {
  1070. inf.hHandle = tool_Info.Interfaces[j].hHandle;
  1071. CRect rect = tool_Info.Interfaces[j].rect;
  1072. if (!rect.IsRectEmpty())
  1073. {
  1074. inf.rect = tool_Info.Interfaces[j].rect;
  1075. }
  1076. if (tool.Type == TOOL_TYPE::TOOL_BY_PROT)
  1077. {
  1078. tool_Info.Interfaces[j].bShow = inf.bShow;
  1079. }
  1080. else
  1081. {
  1082. inf.bShow = tool_Info.Interfaces[j].bShow;
  1083. }
  1084. tool_Info.Interfaces[j].strName = inf.strName;
  1085. tool_Info.Interfaces[j].nUseCount = inf.nUseCount;
  1086. tool_Info.Interfaces[j].strParentName = inf.strParentName;
  1087. }
  1088. }
  1089. }
  1090. /////////////////////////////////////////////////////////////////
  1091. // 更新新工具
  1092. void CTaskWindow::UpdateNewTool(const CString& strToolShowName, TOOL tool_Info, bool bIsLoad )
  1093. {
  1094. CString strToolRealName = GetToolRealname(strToolShowName);
  1095. // 查询对应的工具
  1096. TOOL newTool = g_pTaskView->m_wndTool.GetToolByName(strToolRealName);
  1097. newTool.strShowName = strToolShowName;
  1098. // 获取句柄
  1099. newTool.hHandle = tool_Info.hHandle;
  1100. newTool.rect = tool_Info.rect;
  1101. newTool.strInfo = tool_Info.strInfo;
  1102. newTool.strLinkName = tool_Info.strLinkName;
  1103. newTool.nUseCount = tool_Info.nUseCount;
  1104. for (unsigned int j = 0; j < newTool.Interfaces.size(); j++)
  1105. {
  1106. TOOL_INTERFACE& inf = newTool.Interfaces[j];
  1107. inf.strParentName = strToolShowName;
  1108. inf.hHandle = tool_Info.Interfaces[j].hHandle;
  1109. inf.rect = tool_Info.Interfaces[j].rect;
  1110. inf.nUseCount = tool_Info.Interfaces[j].nUseCount;
  1111. }
  1112. USES_CONVERSION;
  1113. char * s_str = T2A(strToolShowName);
  1114. g_Logger.Info(0, __FILE__, __LINE__, "Task[%d] Add Tool: %s ",m_nIndex, s_str);
  1115. // 从dll获取工具指针
  1116. if (!GetToolPtrByDll(newTool))
  1117. {
  1118. CString strMsg;
  1119. strMsg.Format(_T("Task[%d] %s 工具加载dll工具失败!"),m_nIndex, newTool.strShowName);
  1120. USES_CONVERSION;
  1121. char * s_str = T2A(strMsg);
  1122. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  1123. return;
  1124. }
  1125. if (newTool.pDllPtr != NULL)
  1126. {
  1127. //首先注册日志回调,以便在主框架中显示所有的工具日志
  1128. newTool.pDllPtr->setReceLogCallBack(ToolLogCallback, (long long)g_pMainFrame);
  1129. //注册工具状态回调,以便在主框架中显示工具状态
  1130. newTool.pDllPtr->setReceToolStateCallBack(ToolStateCallback, (long long)this);
  1131. //注册工具中的执行回调,以便在工具中执行当前工具
  1132. newTool.pDllPtr->setOnExecuteCallBack(ToolOnExecuteCallback, (long long)this);
  1133. //注册工具中的执行回调,以便在工具中执行当前工具
  1134. newTool.pDllPtr->setToolBusyCallBack(ToolBusyCallback, (long long)this);
  1135. m_SelTools.push_back(newTool);
  1136. //初始化工具
  1137. newTool.pDllPtr->InitTool(g_pMainFrame->GetActiveView(), m_strTaskName, newTool.strShowName);
  1138. }
  1139. if (! bIsLoad)
  1140. {
  1141. if (BCGPMessageBox(_T("是否执行自动数据链接 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("SmartLink .....")) == IDYES)
  1142. SmartLink();
  1143. }
  1144. Invalidate(TRUE);
  1145. }
  1146. /////////////////////////////////////////////////////////////////
  1147. // 更新所有节点的连接信息
  1148. void CTaskWindow::UpdateLink()
  1149. {
  1150. // 遍历所有节点,更新对应的句柄信息
  1151. for (unsigned int i = 0; i < m_Links.size(); i++)
  1152. {
  1153. LINK& lnk = m_Links[i];
  1154. for (unsigned int m = 0; m < m_SelTools.size(); m++)
  1155. {
  1156. TOOL& tool = m_SelTools[m];
  1157. for (unsigned int n = 0; n < tool.Interfaces.size(); n++)
  1158. {
  1159. TOOL_INTERFACE& inf = tool.Interfaces[n];
  1160. if (IsSameInterface(lnk.source, inf))
  1161. {
  1162. lnk.source = inf;
  1163. break;
  1164. }
  1165. else if (IsSameInterface(lnk.dest, inf))
  1166. {
  1167. lnk.dest = inf;
  1168. break;
  1169. }
  1170. }
  1171. }
  1172. }
  1173. }
  1174. /////////////////////////////////////////////////////////////////
  1175. // 建立连接
  1176. bool CTaskWindow::MakeLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest, bool bShow)
  1177. {
  1178. // 首先检查一下是否有key相同的接口
  1179. LINK_MAP::iterator iter;
  1180. for (iter = m_Links.begin(); iter != m_Links.end(); iter++)
  1181. {
  1182. if (IsSameInterface(dest, iter->dest))
  1183. {
  1184. // 替换现有link
  1185. iter->source = source;
  1186. CString str;
  1187. str.Format(_T("Task[%d] Update link: %s-%s to %s-%s"),m_nIndex,
  1188. source.strParentName, source.strName,
  1189. dest.strParentName, dest.strName);
  1190. USES_CONVERSION;
  1191. char * s_str = T2A(str);
  1192. g_Logger.Debug(0, __FILE__, __LINE__, s_str);
  1193. return TRUE;
  1194. }
  1195. }
  1196. // 否则添加一个新的link
  1197. LINK newLink;
  1198. newLink.source = source;
  1199. newLink.dest = dest;
  1200. newLink.bShow = bShow;
  1201. m_Links.push_back(newLink);
  1202. CString strMsg;
  1203. strMsg.Format(_T("Task[%d] Make link: %s-%s to %s-%s"),m_nIndex,
  1204. newLink.source.strParentName, newLink.source.strName,
  1205. newLink.dest.strParentName, newLink.dest.strName);
  1206. //TRACE(str);
  1207. USES_CONVERSION;
  1208. char * s_str = T2A(strMsg);
  1209. g_Logger.Info(0, __FILE__, __LINE__, s_str);
  1210. return TRUE;
  1211. }
  1212. // 建立连接
  1213. bool CTaskWindow::MakeTestLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest)
  1214. {
  1215. // 首先检查一下是否有key相同的接口
  1216. LINK_MAP::iterator iter;
  1217. for (iter = m_TsetLinks.begin(); iter != m_TsetLinks.end(); iter++)
  1218. {
  1219. if (IsSameInterface(dest, iter->dest))
  1220. {
  1221. // 替换现有link
  1222. iter->source = source;
  1223. TRACE(_T("Update link: %s-%s to %s-%s\n"),
  1224. source.strParentName, source.strName,
  1225. dest.strParentName, dest.strName);
  1226. return TRUE;
  1227. }
  1228. }
  1229. // 否则添加一个新的link
  1230. LINK newLink;
  1231. newLink.source = source;
  1232. newLink.dest = dest;
  1233. m_TsetLinks.clear();
  1234. m_TsetLinks.push_back(newLink);
  1235. TRACE(_T("Make link: %s-%s to %s-%s\n"),
  1236. newLink.source.strParentName, newLink.source.strName,
  1237. newLink.dest.strParentName, newLink.dest.strName);
  1238. return TRUE;
  1239. }
  1240. /////////////////////////////////////////////////////////////////
  1241. // 根据句柄转换成对应的TOOL
  1242. TOOL* CTaskWindow::GetToolByHandle(const HTREEITEM& handle)
  1243. {
  1244. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  1245. {
  1246. TOOL& tool = m_SelTools[i];
  1247. if (tool.hHandle == handle)
  1248. {
  1249. return &m_SelTools[i];
  1250. }
  1251. }
  1252. return NULL;
  1253. }
  1254. //////////////////////////////////////////////////////////////////////////
  1255. // 根据显示的名称转换乘对应的TOOL
  1256. TOOL* CTaskWindow::GetToolByShowName(const CString strName)
  1257. {
  1258. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  1259. {
  1260. TOOL& tool = m_SelTools[i];
  1261. if (tool.strShowName == strName)
  1262. {
  1263. return &m_SelTools[i];
  1264. }
  1265. }
  1266. return NULL;
  1267. }
  1268. ////////////////////////////////////////////////////////////////
  1269. // 根据句柄转换成对应的Interface
  1270. TOOL_INTERFACE* CTaskWindow::GetInterfaceByHandle(const HTREEITEM& handle)
  1271. {
  1272. for (unsigned int m = 0; m < m_SelTools.size(); m++)
  1273. {
  1274. TOOL& toolSearch = m_SelTools[m];
  1275. for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
  1276. {
  1277. TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
  1278. if (infSearch.hHandle == handle)
  1279. {
  1280. return &m_SelTools[m].Interfaces[n];
  1281. }
  1282. }
  1283. }
  1284. return NULL;
  1285. }
  1286. ////////////////////////////////////////////////////////////////
  1287. // 根据 名字 转换成对应的Interface
  1288. TOOL_INTERFACE* CTaskWindow::GetInterfaceByName(const CString strParentName, const CString strName)
  1289. {
  1290. for (unsigned int m = 0; m < m_SelTools.size(); m++)
  1291. {
  1292. TOOL& toolSearch = m_SelTools[m];
  1293. if (toolSearch.strShowName.Compare(strParentName) == 0)
  1294. {
  1295. for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
  1296. {
  1297. TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
  1298. if (infSearch.strName.Compare(strName) == 0)
  1299. {
  1300. return &m_SelTools[m].Interfaces[n];
  1301. }
  1302. }
  1303. }
  1304. }
  1305. return NULL;
  1306. }
  1307. /////////////////////////////////////////////////////////////////
  1308. // 重置整个TaskWindow的相关数据
  1309. void CTaskWindow::Reset()
  1310. {
  1311. // 清空数据结构
  1312. //m_SelTools.clear();
  1313. m_Links.clear();
  1314. m_RenameList.clear();
  1315. m_TsetLinks.clear();
  1316. // 清空树形控件
  1317. // m_wndTree.Clear();
  1318. // m_wndTree.Invalidate(TRUE);
  1319. m_editor.DeleteAll();
  1320. m_editor.Clear();
  1321. m_editor.Invalidate(TRUE);
  1322. // TODO:清空多线程任务相关的状态
  1323. // 第一个线程不退出,需要优化
  1324. if (m_nIndex != 0)
  1325. {
  1326. // 为了使线程退出
  1327. m_bExitThread = true;
  1328. // 为了可使挂起的现场继续执行下去
  1329. SetEvent(m_hExecuteEven);
  1330. SetEvent(m_hDoneEven);
  1331. //释放线程相关的句柄
  1332. RELEASE_HANDLE(m_hDoneEven);
  1333. RELEASE_HANDLE(m_hExecuteEven);
  1334. }
  1335. // 一定要记得清理 dll 指针,否则持续退出会崩溃在系统dll里
  1336. for (size_t i = 0; i < m_SelTools.size(); i++)
  1337. {
  1338. RELEASE_BUFFER(m_SelTools.at(i).pDllPtr);
  1339. FreeLibrary(m_SelTools[i].hDllTool);
  1340. }
  1341. //// 2019-3-23 释放选择的工具
  1342. //for (unsigned int i = 0; i < m_SelTools.size(); i++)
  1343. //{
  1344. // // 调用Release
  1345. // if (m_SelTools[i].hDllTool)
  1346. // {
  1347. // // 调用Release接口
  1348. // typedef void(*RELEASE)();
  1349. // RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE);
  1350. // if (Release)
  1351. // {
  1352. // Release();
  1353. // }
  1354. // FreeLibrary(m_SelTools[i].hDllTool);
  1355. // }
  1356. //}
  1357. m_SelTools.clear();
  1358. }
  1359. ////////////////////////////////////////////////////////////////
  1360. // 获取某个Interface相连的接口
  1361. TOOL_INTERFACE* CTaskWindow::GetHigherLinkInterface(const TOOL_INTERFACE& inf)
  1362. {
  1363. // 遍历所有Link
  1364. for (unsigned int j = 0; j < m_Links.size(); j++)
  1365. {
  1366. LINK& lnk = m_Links[j];
  1367. if (IsSameInterface(lnk.dest, inf))
  1368. {
  1369. return &lnk.source;
  1370. }
  1371. }
  1372. return NULL;
  1373. }
  1374. ///////////////////////////////////////////////////////////////
  1375. // 根据Interface获取Tool
  1376. TOOL* CTaskWindow::GetToolByInterface(TOOL_INTERFACE& inf)
  1377. {
  1378. for (unsigned int m = 0; m < m_SelTools.size(); m++)
  1379. {
  1380. TOOL& toolSearch = m_SelTools[m];
  1381. for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
  1382. {
  1383. TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
  1384. if (IsSameInterface(inf, infSearch))
  1385. {
  1386. return &toolSearch;
  1387. }
  1388. }
  1389. }
  1390. // 查找全局变量
  1391. TOOL& toolSearch = g_pMainFrame->m_GlobalValueDlg.m_GV_Tools;
  1392. for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
  1393. {
  1394. TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
  1395. if (IsSameInterface(inf, infSearch))
  1396. {
  1397. return &toolSearch;
  1398. }
  1399. }
  1400. return NULL;
  1401. }
  1402. ///////////////////////////////////////////////////////////////
  1403. // 根据Interface获取Interface
  1404. TOOL_INTERFACE* CTaskWindow::GetInterfaceByInterface(TOOL_INTERFACE& inf)
  1405. {
  1406. for (unsigned int m = 0; m < m_SelTools.size(); m++)
  1407. {
  1408. TOOL& toolSearch = m_SelTools[m];
  1409. for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
  1410. {
  1411. TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
  1412. if (IsSameInterface(inf, infSearch))
  1413. {
  1414. return &infSearch;
  1415. }
  1416. }
  1417. }
  1418. // 查找全局变量
  1419. TOOL& toolSearch = g_pMainFrame->m_GlobalValueDlg.m_GV_Tools;
  1420. for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
  1421. {
  1422. TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
  1423. if (IsSameInterface(inf, infSearch))
  1424. {
  1425. return &infSearch;
  1426. }
  1427. }
  1428. return NULL;
  1429. }
  1430. //////////////////////////////////////////////////////////////////////////
  1431. // 根据Tool获取Tool
  1432. TOOL* CTaskWindow::GetToolByTool(TOOL& tool)
  1433. {
  1434. for (unsigned int m = 0; m < m_SelTools.size(); m++)
  1435. {
  1436. TOOL& toolSearch = m_SelTools[m];
  1437. if (tool.strShowName == toolSearch.strShowName
  1438. && tool.strName == toolSearch.strName
  1439. )
  1440. {
  1441. return &toolSearch;
  1442. }
  1443. }
  1444. return NULL;
  1445. }
  1446. ////////////////////////////////////////////////////////////////////
  1447. // 判断是否是同一个接口
  1448. bool CTaskWindow::IsSameInterface(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest)
  1449. {
  1450. return source.strParentName == dest.strParentName
  1451. && source.strName == dest.strName
  1452. && source.InfDirection == dest.InfDirection
  1453. && source.InfWay == dest.InfWay;
  1454. }
  1455. ///////////////////////////////////////////////////////////
  1456. // 计算连接线的长度
  1457. int CTaskWindow::CalcLinkLineLength(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest)
  1458. {
  1459. int nLength = 0;
  1460. bool bSearch = false;
  1461. /*
  1462. CString strName = m_wndTree.GetItemText(source.hHandle);
  1463. // TRACE(_T("strName: %s\n"), strName);
  1464. for (unsigned int m = 0; m < m_SelTools.size(); m++)
  1465. {
  1466. TOOL& toolSearch = m_SelTools[m];
  1467. for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
  1468. {
  1469. TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
  1470. // CString strName1 = m_wndTree.GetItemText(infSearch.hHandle);
  1471. // TRACE(_T("strName1: %s\n"), strName1);
  1472. if (bSearch)
  1473. {
  1474. CRect rc;
  1475. m_wndTree.GetItemRect(infSearch.hHandle, &rc, TRUE);
  1476. if (rc.right > nLength)
  1477. {
  1478. nLength = rc.right;
  1479. }
  1480. if (IsSameInterface(dest, infSearch))
  1481. {
  1482. return nLength;
  1483. }
  1484. }
  1485. else
  1486. {
  1487. if (IsSameInterface(source, infSearch))
  1488. {
  1489. CRect rc;
  1490. m_wndTree.GetItemRect(source.hHandle, &rc, TRUE);
  1491. nLength = rc.right;
  1492. bSearch = true;
  1493. }
  1494. }
  1495. }
  1496. }
  1497. */
  1498. return nLength;
  1499. }
  1500. /////////////////////////////////////////////////////
  1501. // 通过工具显示的名字查询工具真正的名字
  1502. CString CTaskWindow::GetToolRealname(const CString& strShowName)
  1503. {
  1504. CString strRealName;
  1505. map<CString, CString>::iterator iter;
  1506. for (iter = m_RenameList.begin(); iter != m_RenameList.end(); iter++)
  1507. {
  1508. if (strShowName.Compare(iter->first) == 0)
  1509. {
  1510. strRealName = iter->second;
  1511. return strRealName;
  1512. }
  1513. }
  1514. return strShowName;
  1515. }
  1516. /////////////////////////////////////////////////////////////
  1517. // 计算连线的触发区域
  1518. LINK_RECTS CTaskWindow::CalcLinkRects(const LINK_POINTS& lps)
  1519. {
  1520. LINK_RECTS lrs;
  1521. lrs.rcStart.left = lps.ptStart.x - PORT_WIDTH;
  1522. lrs.rcStart.right = lps.ptCorner1.x;
  1523. lrs.rcStart.top = lps.ptStart.y - HOT_REGION;
  1524. lrs.rcStart.bottom = lps.ptStart.y + HOT_REGION;
  1525. lrs.rcEnd.left = lps.ptCorner4.x;
  1526. lrs.rcEnd.right = lps.ptEnd.x + PORT_WIDTH;
  1527. lrs.rcEnd.top = lps.ptEnd.y - HOT_REGION;
  1528. lrs.rcEnd.bottom = lps.ptEnd.y + HOT_REGION;
  1529. lrs.rcCorner1.left = lps.ptCorner1.x - HOT_REGION;
  1530. lrs.rcCorner1.right = lps.ptCorner1.x + HOT_REGION;
  1531. switch (lps.nMode)
  1532. {
  1533. case 1:
  1534. case 2:
  1535. case 3:
  1536. case 4:
  1537. lrs.rcCorner1.top = lrs.rcStart.top < lrs.rcEnd.top ? lrs.rcStart.top : lrs.rcEnd.top;
  1538. lrs.rcCorner1.bottom = lrs.rcStart.bottom > lrs.rcEnd.bottom ? lrs.rcStart.bottom : lrs.rcEnd.bottom;
  1539. break;
  1540. case 5:
  1541. lrs.rcCorner1.top = lrs.rcStart.top < lrs.rcEnd.top ? lrs.rcStart.top : lrs.rcEnd.top;
  1542. lrs.rcCorner1.bottom = lps.ptCorner2.y;
  1543. break;
  1544. case 6:
  1545. lrs.rcCorner1.top = lps.ptCorner2.y;
  1546. lrs.rcCorner1.bottom = lps.ptStart.y;
  1547. break;
  1548. default:
  1549. break;
  1550. }
  1551. lrs.rcCorner3.left = lps.ptCorner3.x - HOT_REGION;
  1552. lrs.rcCorner3.right = lps.ptCorner3.x + HOT_REGION;
  1553. if (lps.nMode == 5)
  1554. {
  1555. lrs.rcCorner3.top = lps.ptCorner3.y;
  1556. lrs.rcCorner3.bottom = lps.ptEnd.y;
  1557. }if (lps.nMode == 6)
  1558. {
  1559. lrs.rcCorner3.top = lps.ptEnd.y;
  1560. lrs.rcCorner3.bottom = lps.ptCorner3.y;
  1561. }
  1562. lrs.rcCorner2.left = lps.ptCorner3.x;
  1563. lrs.rcCorner2.right = lps.ptCorner1.x;
  1564. lrs.rcCorner2.top = lps.ptCorner3.y - HOT_REGION;
  1565. lrs.rcCorner2.bottom = lps.ptCorner3.y + HOT_REGION;
  1566. return lrs;
  1567. }
  1568. ///////////////////////////////////////////////////////
  1569. // 鼠标左键按下时,激活连线
  1570. void CTaskWindow::OnLButtonDown(UINT nFlags, CPoint point)
  1571. {
  1572. // 循环遍历所有连线区域,查找是否有命中的
  1573. CPoint pt = point;
  1574. m_editor.ScreenToVirtual(pt);
  1575. LINK_MAP::iterator iter;
  1576. // 然后查找命中
  1577. for (iter = m_Links.begin(); iter != m_Links.end(); iter++)
  1578. {
  1579. // 计算这个连线的矩形区域
  1580. LINK_POINTS lps = CalcLinkPoints(*iter);
  1581. LINK_RECTS lrs = CalcLinkRects(lps);
  1582. // 判断鼠标是否命中
  1583. if (PtInRect(&lrs.rcStart, pt) || PtInRect(&lrs.rcEnd, pt) ||
  1584. PtInRect(&lrs.rcCorner1, pt) || PtInRect(&lrs.rcCorner2, pt) ||
  1585. PtInRect(&lrs.rcCorner3, pt)
  1586. )
  1587. {
  1588. // 如果命中,则把这条线设置为命中状态
  1589. iter->bActive = TRUE;
  1590. // 然后把其他连接设置为未命中状态
  1591. for (unsigned int i = 0; i < m_Links.size(); i++)
  1592. {
  1593. if (*iter != m_Links[i])
  1594. {
  1595. m_Links[i].bActive = FALSE;
  1596. }
  1597. }
  1598. // Invalidate(TRUE);
  1599. break;
  1600. }
  1601. else
  1602. {
  1603. //点击空白处,将所有连线设置为未选中状态
  1604. for (unsigned int i = 0; i < m_Links.size(); i++)
  1605. {
  1606. m_Links[i].bActive = FALSE;
  1607. }
  1608. }
  1609. }
  1610. CBCGPStatic::OnLButtonDown(nFlags, point);
  1611. }
  1612. //////////////////////////////////////////////////////////////////////////
  1613. // 当 Item单击时候
  1614. void CTaskWindow::OnItemLButtonDown(const HTREEITEM& handle)
  1615. {
  1616. TOOL* pActiveTool = GetToolByHandle(handle);
  1617. if (pActiveTool == NULL)
  1618. {
  1619. return;
  1620. }
  1621. // 根据Tool的指针调用函数
  1622. if (pActiveTool != NULL)
  1623. {
  1624. DEUBGOBJ obj = pActiveTool->pDllPtr->GetDeubgDispObj();
  1625. g_pTaskView->m_wndDisp.AddImage(obj.mImage);
  1626. g_pTaskView->m_wndDisp.AddOjb(obj.mObj);
  1627. g_pTaskView->m_wndDisp.Refresh();
  1628. }
  1629. }
  1630. ////////////////////////////////////////////////////////
  1631. // 当Item双击时
  1632. void CTaskWindow::OnItemDblclk(const HTREEITEM& handle)
  1633. {
  1634. // 根据句柄查询到工具
  1635. TOOL* pActiveTool = GetToolByHandle(handle);
  1636. if (pActiveTool == NULL)
  1637. {
  1638. return;
  1639. }
  1640. if (pActiveTool->Type == TOOL_TYPE::TOOL_BY_PROT && pActiveTool->strLinkName.IsEmpty() )
  1641. {
  1642. CDialogLink dlgLink;
  1643. dlgLink.m_InfType = INF_TYPE::INF_VALUE_1;
  1644. dlgLink.m_LinkVarType = VAR_TYPE::ALL_Var;
  1645. dlgLink.m_Direction = INF_DIRECTION::INF_OUT;
  1646. for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++)
  1647. {
  1648. TOOL_INTERFACE inf = pActiveTool->Interfaces[i];
  1649. if (inf.InfDirection == INF_DIRECTION::INF_OUT && inf.bShow == true)
  1650. {
  1651. dlgLink.m_LinkVarType = inf.VarType;
  1652. }
  1653. }
  1654. if (dlgLink.DoModal() == IDOK)
  1655. {
  1656. for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++)
  1657. {
  1658. TOOL_INTERFACE inf = pActiveTool->Interfaces[i];
  1659. if (inf.InfDirection == INF_DIRECTION::INF_IN && inf.VarType == dlgLink.m_SelInterface.VarType)
  1660. {
  1661. TOOL_INTERFACE* pInfSource = GetInterfaceByInterface(dlgLink.m_SelInterface);
  1662. TOOL_INTERFACE* pInfDest = GetInterfaceByInterface(inf);
  1663. ASSERT(pInfDest != NULL);
  1664. if (pInfDest != NULL && pInfSource != NULL /*&& dlgLink.m_nTaskIndex != TASK_SYSTEM_GV*/)
  1665. {
  1666. if (dlgLink.m_nTaskIndex == TASK_SYSTEM_GV)
  1667. {
  1668. pInfSource = g_pMainFrame->m_GlobalValueDlg.GetInterfaceByInterface(dlgLink.m_SelInterface);
  1669. for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++)
  1670. {
  1671. TOOL_INTERFACE& inf = pActiveTool->Interfaces[i];
  1672. if (inf.InfDirection == INF_DIRECTION::INF_OUT && inf.VarType == dlgLink.m_SelInterface.VarType)
  1673. {
  1674. inf.bShow = true;
  1675. }
  1676. }
  1677. }
  1678. // 内部引用计数加一
  1679. pInfSource->nUseCount ++;
  1680. pInfDest->nUseCount++;
  1681. const TOOL_INTERFACE source = *pInfSource;
  1682. const TOOL_INTERFACE dest = *pInfDest;
  1683. MakeLink(source, dest, false);
  1684. pInfDest->bShow = true;
  1685. CString strLink;
  1686. strLink.Format(_T("%s.%s.Q"),
  1687. dlgLink.m_SelInterface.strParentName,
  1688. dlgLink.m_SelInterface.strName);
  1689. pActiveTool->strLinkName = strLink;
  1690. UpdateTools();
  1691. }
  1692. else
  1693. {
  1694. CString strMsg;
  1695. strMsg.Format(_T("Task[%d] Link Error %s.%s --> %s.%s "), m_nIndex,
  1696. dlgLink.m_SelInterface.strParentName, dlgLink.m_SelInterface.strName, inf.strParentName, inf.strName);
  1697. USES_CONVERSION;
  1698. char * s_str = T2A(strMsg);
  1699. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }
  1705. // 根据Tool的指针调用函数
  1706. if (pActiveTool != NULL)
  1707. {
  1708. if (pActiveTool->bEnable == false)
  1709. {
  1710. g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作....."));
  1711. return;
  1712. }
  1713. pActiveTool->pDllPtr->ShowDialog(m_strTaskName, pActiveTool->strShowName);
  1714. }
  1715. }
  1716. ////////////////////////////////////////////////////////
  1717. // 当Item双击时 子节点
  1718. void CTaskWindow::OnItemNodeDblclk(const HTREEITEM& handle)
  1719. {
  1720. TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle);
  1721. if (pInf != NULL)
  1722. {
  1723. if (pInf->InfDirection == INF_DIRECTION::INF_IN && pInf->nUseCount == 0)
  1724. {
  1725. if (BCGPMessageBox(_T("是否添加 Prot 端口"), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Add Prot .....")) == IDYES)
  1726. {
  1727. TOOL* pDestTool = GetToolByShowName(pInf->strParentName);// 点击的模块(工具实体模块)
  1728. pInf->rect.TopLeft().x -= 150;
  1729. pInf->rect.TopLeft().y -= 5;
  1730. TOOL newTool;
  1731. newTool.strName = _T("InPutProt");
  1732. newTool.strShowName = _T("InPutProt");
  1733. newTool.rect = pInf->rect;
  1734. CString strShowName;
  1735. AddNewTools2(newTool, &strShowName);
  1736. UpdateTools();
  1737. TOOL* pSourceTool = GetToolByShowName(strShowName);
  1738. if (pSourceTool != NULL)
  1739. {
  1740. bool bFindStatus = false;
  1741. //////////////////////////////////////////////////////////////////////////
  1742. // 此处搜索的是Prot模块
  1743. for (UINT i = 0; i < pSourceTool->Interfaces.size(); i++)
  1744. {
  1745. TOOL_INTERFACE& inf = pSourceTool->Interfaces[i];
  1746. if (inf.InfDirection == INF_DIRECTION::INF_OUT)
  1747. {
  1748. TOOL_INTERFACE* pDestInf = GetInterfaceByHandle(handle);
  1749. if (inf.VarType == pDestInf->VarType && inf.strParentName != pDestInf->strParentName)
  1750. {
  1751. // 如果再prot模块里能找到对应的数据类型,就可以创建数据链接(源数据)
  1752. bFindStatus = true;
  1753. inf.bShow = true;
  1754. BOOL status = AddLink(inf, *pDestInf);
  1755. if (!status)
  1756. {
  1757. g_Logger.Error(0, NULL, NULL, "Task[%d] Link Error %s.%s --> %s.%s ",m_nIndex, inf.strParentName, inf.strName, pDestInf->strParentName, pDestInf->strName);
  1758. }
  1759. CString strMsg;
  1760. strMsg.Format(_T("Task[%d] Link OK %s.%s --> %s.%s "),m_nIndex, inf.strParentName, inf.strName, pDestInf->strParentName, pDestInf->strName);
  1761. USES_CONVERSION;
  1762. char * s_str = T2A(strMsg);
  1763. g_Logger.Debug(0, __FILE__, __LINE__, s_str);
  1764. }
  1765. }
  1766. }
  1767. if (!bFindStatus)
  1768. {
  1769. TOOL_INTERFACE* pDestInf = GetInterfaceByHandle(handle);
  1770. if (pDestInf)
  1771. {
  1772. g_Logger.Error(0, NULL, NULL, "Task[%d] Find Prot Error %s.%s --> %s.%s [%d]",m_nIndex, pDestInf->strParentName, pDestInf->strName, pDestInf->VarType);
  1773. }
  1774. else
  1775. {
  1776. g_Logger.Error(0, NULL, NULL, "Task[%d] Find Prot Error",m_nIndex);
  1777. }
  1778. }
  1779. UpdateTools();
  1780. //重新排序too的序号,使Prot序号 小于当前工具的序号
  1781. SortProtToolID (pSourceTool,pDestTool);
  1782. }
  1783. }
  1784. }
  1785. if (pInf->InfDirection == INF_DIRECTION::INF_OUT)
  1786. {
  1787. ShowNodeWatch(pInf);
  1788. }
  1789. }
  1790. }
  1791. ////////////////////////////////////////////////////////////
  1792. // 鼠标右键删除的时候
  1793. bool CTaskWindow::OnItemEnable(const HTREEITEM& handle)
  1794. {
  1795. // 根据句柄查询到工具
  1796. TOOL* pActiveTool = GetToolByHandle(handle);
  1797. ASSERT(pActiveTool != NULL);
  1798. if (pActiveTool == NULL)
  1799. {
  1800. return false;
  1801. }
  1802. CString strToolName = pActiveTool->strShowName;
  1803. // BCGPMessageBox(strToolName);
  1804. pActiveTool->bEnable = !pActiveTool->bEnable;
  1805. return pActiveTool->bEnable;
  1806. }
  1807. ////////////////////////////////////////////////////////////
  1808. // 鼠标右键删除的时候
  1809. void CTaskWindow::OnItemDelete(const HTREEITEM& handle)
  1810. {
  1811. // 根据句柄查询到工具
  1812. TOOL* pActiveTool = GetToolByHandle(handle);
  1813. ASSERT(pActiveTool != NULL);
  1814. if (pActiveTool == NULL)
  1815. {
  1816. return;
  1817. }
  1818. CString strToolName = pActiveTool->strShowName;
  1819. // 删除选择工具集中的信息
  1820. vector<TOOL>::iterator itTool;
  1821. for (itTool = m_SelTools.begin(); itTool != m_SelTools.end(); )
  1822. {
  1823. if (itTool->strShowName.Compare(strToolName) == 0)
  1824. {
  1825. RELEASE_BUFFER(itTool->pDllPtr);
  1826. FreeLibrary(itTool->hDllTool);
  1827. itTool = m_SelTools.erase(itTool);
  1828. break;
  1829. }
  1830. else
  1831. {
  1832. ++itTool;
  1833. }
  1834. }
  1835. // 删除重命名列表中的信息
  1836. m_RenameList.erase(strToolName);
  1837. m_editor.RedrawWindow();
  1838. Invalidate(TRUE);
  1839. CString strMsg;
  1840. strMsg.Format(_T("Task[%d] Delete Tools:%s ") ,m_nIndex, strToolName);
  1841. USES_CONVERSION;
  1842. char * s_str = T2A(strMsg);
  1843. g_Logger.Warn(0, __FILE__, __LINE__, s_str);
  1844. }
  1845. bool CTaskWindow::IsLink(const HTREEITEM& handle)
  1846. {
  1847. // 根据句柄查询到工具
  1848. TOOL* pActiveTool = GetToolByHandle(handle);
  1849. //ASSERT(pActiveTool != NULL);
  1850. if (pActiveTool == NULL)
  1851. {
  1852. return false;
  1853. }
  1854. CString strToolName = pActiveTool->strShowName;
  1855. bool bIsLink = false;
  1856. vector<LINK>::iterator itLink;
  1857. for (itLink = m_Links.begin(); itLink != m_Links.end(); )
  1858. {
  1859. if ((itLink->source.strParentName.Compare(strToolName) == 0)
  1860. || (itLink->dest.strParentName.Compare(strToolName) == 0))
  1861. {
  1862. //itLink = m_Links.erase(itLink);
  1863. CString strMsg;
  1864. strMsg.Format(_T("Task[%d] Link Protected %s.%s ---> %s.%s"),m_nIndex, itLink->source.strParentName, itLink->source.strName, itLink->dest.strParentName, itLink->dest.strName);
  1865. USES_CONVERSION;
  1866. char * s_str = T2A(strMsg);
  1867. g_Logger.Debug(0, __FILE__, __LINE__, s_str);
  1868. bIsLink = true;
  1869. break;
  1870. }
  1871. else
  1872. {
  1873. ++itLink;
  1874. }
  1875. }
  1876. return bIsLink;
  1877. }
  1878. // 判断是否受保护
  1879. bool CTaskWindow::IsProtected(const HTREEITEM& handle)
  1880. {
  1881. // 根据句柄查询到工具
  1882. TOOL* pTool = GetToolByHandle(handle);
  1883. ASSERT(pTool != NULL);
  1884. if (pTool == NULL)
  1885. {
  1886. return true;
  1887. }
  1888. if (pTool->nUseCount)
  1889. {
  1890. CString strMsg;
  1891. strMsg.Format(_T("Task[%d] Tool Protected %s UseCount[ %d ]"),m_nIndex, pTool->strShowName, pTool->nUseCount);
  1892. USES_CONVERSION;
  1893. char * s_str = T2A(strMsg);
  1894. g_Logger.Debug(0, __FILE__, __LINE__, s_str);
  1895. return true;
  1896. }
  1897. // 遍历本工具下的所有接口
  1898. bool bIsProtected = false;
  1899. for (unsigned int k = 0; k < pTool->Interfaces.size(); k++)
  1900. {
  1901. const TOOL_INTERFACE& inf = pTool->Interfaces[k];
  1902. if (inf.nUseCount)
  1903. {
  1904. CString strMsg;
  1905. strMsg.Format(_T("Task[%d] Prot Protected %s.%s UseCount[ %d ]"),m_nIndex, inf.strParentName, inf.strName, inf.nUseCount);
  1906. USES_CONVERSION;
  1907. char * s_str = T2A(strMsg);
  1908. g_Logger.Debug(0, __FILE__, __LINE__, s_str);
  1909. bIsProtected = true;
  1910. }
  1911. }
  1912. return bIsProtected;
  1913. }
  1914. ////////////////////////////////////////////////////////////////
  1915. // 用户右键菜单选择了工具重命名
  1916. void CTaskWindow::OnItemToolRename(const HTREEITEM& handle)
  1917. {
  1918. // 根据句柄查询到工具
  1919. TOOL* pActiveTool = GetToolByHandle(handle);
  1920. CString strOldName = pActiveTool->strShowName;
  1921. if (pActiveTool->bEnable == false)
  1922. {
  1923. g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作....."));
  1924. return;
  1925. }
  1926. //修改处理模块名称
  1927. CToolRenameDlg ToolRename;
  1928. ToolRename.SetToolName(strOldName);
  1929. if (ToolRename.DoModal() == IDOK)
  1930. {
  1931. CString strNewName = ToolRename.GetToolName();
  1932. CString strInfo;
  1933. strInfo.Format(_T("Task[%d] 修改工具名称( %s )为( %s)"),m_nIndex, strOldName, strNewName);
  1934. // 修改界面显示的名字
  1935. pActiveTool->strShowName = strNewName;
  1936. CDiagramEntityContainer* objs = static_cast<CDiagramEntityContainer*> (m_editor.GetDiagramEntityContainer());
  1937. if (objs)
  1938. {
  1939. for (UINT nIndex = 0; nIndex < objs->GetSize(); nIndex++)
  1940. {
  1941. CFunctionBlock& obj = *(CFunctionBlock*)objs->GetAt(nIndex);
  1942. if (obj.Tools.strShowName.Compare(strOldName) == 0)
  1943. {
  1944. obj.Tools.strShowName = strNewName;
  1945. break;
  1946. }
  1947. }
  1948. }
  1949. // 界面重绘
  1950. Invalidate(TRUE);
  1951. OUTPUT_MSG msg;
  1952. msg.strMsg = strInfo;
  1953. USES_CONVERSION;
  1954. char * s_str = T2A(msg.strMsg);
  1955. g_Logger.Debug(0, __FILE__, __LINE__, s_str);
  1956. //g_pMainFrame->SendMessage(DOC_CHANGE);
  1957. // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步)
  1958. for (UINT i = 0; i < m_SelTools.size(); i++)
  1959. {
  1960. for (UINT j = 0; j < m_SelTools[i].Interfaces.size(); j++)
  1961. {
  1962. TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j];
  1963. if (inf.strParentName.Compare(strOldName) == 0)
  1964. {
  1965. inf.strParentName = strNewName;
  1966. }
  1967. }
  1968. }
  1969. // 修改重命名链表
  1970. m_RenameList.erase(strOldName);
  1971. m_RenameList.insert(pair<CString, CString>(strNewName, pActiveTool->strName));
  1972. // 修改Link信息
  1973. for (UINT i = 0; i < m_Links.size(); i++)
  1974. {
  1975. LINK& link = m_Links[i];
  1976. if (link.source.strParentName.Compare(strOldName) == 0)
  1977. {
  1978. link.source.strParentName = strNewName;
  1979. }
  1980. else if (link.dest.strParentName.Compare(strOldName) == 0)
  1981. {
  1982. link.dest.strParentName = strNewName;
  1983. }
  1984. }
  1985. }
  1986. }
  1987. //////////////////////////////////////////////////////////////////////////
  1988. // 编辑工具名称
  1989. void CTaskWindow::ToolRename(TOOL* pTool, const CString strNewName)
  1990. {
  1991. CString strOldName = pTool->strShowName;
  1992. if (pTool->bEnable == false)
  1993. {
  1994. g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作....."));
  1995. return;
  1996. }
  1997. // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步)
  1998. for (UINT i = 0; i < m_SelTools.size(); i++)
  1999. {
  2000. TOOL & tool = m_SelTools[i];
  2001. if (tool.strShowName == strNewName)
  2002. {
  2003. CString strMsg;
  2004. strMsg.Format(_T("Task[%d] 修改工具名称( %s )为( %s) 失败"),m_nIndex, strOldName, strNewName);
  2005. USES_CONVERSION;
  2006. char * s_str = T2A(strMsg);
  2007. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2008. return;
  2009. }
  2010. }
  2011. //修改处理模块名称
  2012. {
  2013. CString strInfo;
  2014. strInfo.Format(_T("Task[%d] 修改工具名称( %s )为( %s)"),m_nIndex, strOldName, strNewName);
  2015. // 修改界面显示的名字
  2016. pTool->strShowName = strNewName;
  2017. CDiagramEntityContainer* objs = static_cast<CDiagramEntityContainer*> (m_editor.GetDiagramEntityContainer());
  2018. if (objs)
  2019. {
  2020. for (UINT nIndex = 0; nIndex < objs->GetSize(); nIndex++)
  2021. {
  2022. CFunctionBlock& obj = *(CFunctionBlock*)objs->GetAt(nIndex);
  2023. if (obj.Tools.strShowName.Compare(strOldName) == 0)
  2024. {
  2025. obj.Tools.strShowName = strNewName;
  2026. break;
  2027. }
  2028. }
  2029. }
  2030. // 界面重绘
  2031. Invalidate(TRUE);
  2032. USES_CONVERSION;
  2033. char * s_str = T2A(strInfo);
  2034. g_Logger.Debug(0, __FILE__, __LINE__, s_str);
  2035. //g_pMainFrame->SendMessage(DOC_CHANGE);
  2036. // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步)
  2037. for (UINT i = 0; i < m_SelTools.size(); i++)
  2038. {
  2039. for (UINT j = 0; j < m_SelTools[i].Interfaces.size(); j++)
  2040. {
  2041. TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j];
  2042. if (inf.strParentName.Compare(strOldName) == 0)
  2043. {
  2044. inf.strParentName = strNewName;
  2045. }
  2046. }
  2047. }
  2048. // 修改重命名链表
  2049. m_RenameList.erase(strOldName);
  2050. m_RenameList.insert(pair<CString, CString>(strNewName, pTool->strName));
  2051. // 修改Link信息
  2052. for (UINT i = 0; i < m_Links.size(); i++)
  2053. {
  2054. LINK& link = m_Links[i];
  2055. if (link.source.strParentName.Compare(strOldName) == 0)
  2056. {
  2057. link.source.strParentName = strNewName;
  2058. }
  2059. else if (link.dest.strParentName.Compare(strOldName) == 0)
  2060. {
  2061. link.dest.strParentName = strNewName;
  2062. }
  2063. }
  2064. }
  2065. }
  2066. //////////////////////////////////////////////////////////
  2067. // 右键菜单Link to/from ...
  2068. void CTaskWindow::OnItemLink(const HTREEITEM& source, UINT nLinkDestIndex)
  2069. {
  2070. ASSERT(nLinkDestIndex >= 0);
  2071. TOOL_INTERFACE* pInfSource = GetInterfaceByHandle(source);
  2072. TOOL_INTERFACE* pInfDest = &m_PopLinkNodes.at(nLinkDestIndex);
  2073. // 建立连接
  2074. if (pInfSource->InfDirection == INF_IN)
  2075. {
  2076. AddLink(*pInfDest, *pInfSource);
  2077. }
  2078. else
  2079. {
  2080. AddLink(*pInfSource, *pInfDest);
  2081. }
  2082. // 清空右键link链表
  2083. m_PopLinkNodes.clear();
  2084. }
  2085. /////////////////////////////////////////////////////////
  2086. // 右键菜单UnLink
  2087. void CTaskWindow::OnItemUnLink(HTREEITEM hSelItem)
  2088. {
  2089. // 查找当前的link信息,取消与之相关的连接
  2090. bool bUnLink = false;
  2091. vector<LINK>::iterator it;
  2092. for (it = m_Links.begin(); it != m_Links.end(); )
  2093. {
  2094. LINK& link = *it;
  2095. if (link.source.hHandle == hSelItem
  2096. || link.dest.hHandle == hSelItem)
  2097. {
  2098. TOOL_INTERFACE* pSourceInf = GetInterfaceByInterface(link.source);
  2099. ASSERT(pSourceInf != NULL);
  2100. pSourceInf->nUseCount--;
  2101. TOOL_INTERFACE* pDestInf = GetInterfaceByInterface(link.dest);
  2102. ASSERT(pDestInf != NULL);
  2103. pDestInf->nUseCount--;
  2104. it = m_Links.erase(it);
  2105. bUnLink = true;
  2106. }
  2107. else
  2108. {
  2109. it++;
  2110. }
  2111. }
  2112. if (!bUnLink)
  2113. {
  2114. TOOL_INTERFACE* pInf = GetInterfaceByHandle(hSelItem);
  2115. if (pInf != NULL)
  2116. {
  2117. pInf->nUseCount = 0;
  2118. }
  2119. }
  2120. }
  2121. ////////////////////////////////////////////////////////
  2122. // 根据右键菜单获取可以link的接口
  2123. INF_DIRECTION CTaskWindow::GetPopLinkNodes(std::vector<TOOL_INTERFACE>& PopLinkNodes, HTREEITEM hSelItem)
  2124. {
  2125. m_PopLinkNodes.clear();
  2126. INF_DIRECTION dir = INF_NONE;
  2127. // 首先找到用户选中的接口
  2128. TOOL_INTERFACE* pInf = GetInterfaceByHandle(hSelItem);
  2129. if (pInf == NULL)
  2130. {
  2131. return dir;
  2132. }
  2133. dir = pInf->InfDirection;
  2134. // 然后继续寻找所有的本接口可以关联的接口
  2135. for (unsigned int m = 0; m < m_SelTools.size(); m++)
  2136. {
  2137. TOOL& toolSearch = m_SelTools[m];
  2138. for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
  2139. {
  2140. TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
  2141. if (IsSameInterface(*pInf, infSearch))
  2142. {
  2143. continue;
  2144. }
  2145. // IN/OUT匹配,并且数据类型一致,并且不从属于同一个Tool
  2146. // 则认为是可以link的接口
  2147. if (pInf->VarType == (infSearch.VarType)
  2148. && pInf->InfDirection != infSearch.InfDirection
  2149. && pInf->strParentName.Compare(infSearch.strParentName) != 0
  2150. )
  2151. {
  2152. m_PopLinkNodes.push_back(infSearch);
  2153. }
  2154. }
  2155. }
  2156. PopLinkNodes = m_PopLinkNodes;
  2157. return dir;
  2158. }
  2159. //////////////////////////////////////////////////
  2160. // 为Tool添加执行结果的图标
  2161. void CTaskWindow::DrawToolColour(NMLVCUSTOMDRAW* pLVCD)
  2162. {
  2163. pLVCD->clrText = globalData.clrBarText; // 这样设置文字颜色
  2164. HTREEITEM hItem = (HTREEITEM)pLVCD->nmcd.dwItemSpec;
  2165. LPTOOL pTool = GetToolByHandle(hItem);
  2166. if ((pTool == NULL) ||
  2167. ((pTool->nExecCode == RT_NONE) && (pTool->nToolState != TOOL_ERROR)))
  2168. {
  2169. return;
  2170. }
  2171. // 用于在当前工具返回错误时候,用不同颜色标记
  2172. if (pTool->nToolState == TOOL_ERROR)
  2173. {
  2174. pLVCD->clrTextBk = RGB(255, 0, 0); // 设置文字背景颜色
  2175. }
  2176. else
  2177. {
  2178. pLVCD->clrTextBk = globalData.clrBarHilite; // 设置文字背景颜色
  2179. pLVCD->clrText = globalData.clrBarText;
  2180. // ::GetSysColor(COLOR_HIGHLIGHT);
  2181. // ::GetSysColorBrush(COLOR_HIGHLIGHT);
  2182. }
  2183. }
  2184. //////////////////////////////////////////////////
  2185. // 为Tool添加执行结果的图标
  2186. void CTaskWindow::DrawToolResult(NMLVCUSTOMDRAW* pLVCD)
  2187. {
  2188. /*
  2189. HTREEITEM hItem = (HTREEITEM)pLVCD->nmcd.dwItemSpec;
  2190. LPTOOL pTool = GetToolByHandle(hItem);
  2191. if ((pTool == NULL) ||
  2192. ((pTool->nExecCode == RT_NONE) && (pTool->nToolState != TOOL_ERROR)))
  2193. {
  2194. return;
  2195. }
  2196. CRect textRect;
  2197. m_wndTree.GetItemRect(hItem, &textRect, TRUE);
  2198. CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
  2199. // 画图采用双缓冲
  2200. CDC memDC;
  2201. memDC.CreateCompatibleDC(pDC);
  2202. // 选择图片对象
  2203. CBitmap *pOldBitmap = NULL;
  2204. // 位图长宽获取
  2205. BITMAP bmInfo;
  2206. if (pTool->nToolState == TOOL_ERROR)
  2207. {
  2208. memDC.SelectObject(&m_Bitmap[0]);
  2209. m_Bitmap[0].GetObject(sizeof(BITMAP), &bmInfo);
  2210. }
  2211. else if (pTool->bEnable == false)//如果工具未启用,图标设置为新的
  2212. {
  2213. memDC.SelectObject(&m_Bitmap[0]);
  2214. m_Bitmap[0].GetObject(sizeof(BITMAP), &bmInfo);
  2215. }
  2216. else if (pTool->nExecCode == RT_SUCCESS)
  2217. {
  2218. memDC.SelectObject(&m_Bitmap[2]);
  2219. m_Bitmap[2].GetObject(sizeof(BITMAP), &bmInfo);
  2220. }
  2221. else
  2222. {
  2223. memDC.SelectObject(&m_Bitmap[1]);
  2224. m_Bitmap[1].GetObject(sizeof(BITMAP), &bmInfo);
  2225. }
  2226. // 输出图片
  2227. pDC->BitBlt(textRect.right, textRect.top, bmInfo.bmWidth, bmInfo.bmHeight, &memDC, 0, 0, SRCCOPY);
  2228. // 删除DC
  2229. memDC.SelectObject(pOldBitmap);
  2230. memDC.DeleteDC();
  2231. */
  2232. }
  2233. //////////////////////////////////////////////////////////
  2234. // 任务窗口序列化
  2235. BOOL CTaskWindow::DoSerialize(CArchive& ar)
  2236. {
  2237. // 保存工具
  2238. if (ar.IsStoring())
  2239. {
  2240. if (!SaveToFile(ar))
  2241. {
  2242. return FALSE;
  2243. }
  2244. }
  2245. // 读取工具信息
  2246. else
  2247. {
  2248. theApp.UpdateSplash(_T("CTaskWindow::DoSerialize()"));
  2249. // 重置链表
  2250. m_RenameList.clear();
  2251. // 2019-3-23 释放选择的工具
  2252. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  2253. {
  2254. // 调用Release
  2255. if (m_SelTools[i].hDllTool)
  2256. {
  2257. // 调用Release接口
  2258. typedef void(*RELEASE)();
  2259. RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE);
  2260. if (Release)
  2261. {
  2262. Release();
  2263. }
  2264. FreeLibrary(m_SelTools[i].hDllTool);
  2265. }
  2266. }
  2267. m_SelTools.clear();
  2268. if (!LoadFromFile(ar))
  2269. {
  2270. return FALSE;
  2271. }
  2272. }
  2273. // 这段代码之前需要保存流程栏的工具和连线
  2274. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  2275. {
  2276. TOOL& tool = m_SelTools[i];
  2277. USES_CONVERSION;
  2278. char * s_str = T2A(tool.strShowName);
  2279. try
  2280. {
  2281. theApp.UpdateSplash(tool.strShowName + _T("DoSerialize()"));
  2282. tool.pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion);
  2283. }
  2284. catch (...)
  2285. {
  2286. // CString strMsg;
  2287. // strMsg.Format(_T("%s Tool Serialize Error"), tool.strShowName);
  2288. //
  2289. // OUTPUT_MSG msg;
  2290. // msg.bWay = MSG_WAY::_ERROR;
  2291. // msg.strMsg = strMsg;
  2292. g_Logger.Error(0, __FILE__, __LINE__, ("%s Tool Serialize Error"), s_str);
  2293. }
  2294. }
  2295. m_editor.RedrawWindow();
  2296. return TRUE;
  2297. }
  2298. // 保存工具信息到文件中
  2299. BOOL CTaskWindow::SaveToFile(CArchive& ar)
  2300. {
  2301. int nParanum;//参数数量
  2302. nParanum = 8;//以下参数的数量
  2303. ar << nParanum;
  2304. ar << (int)1 << (int)m_editor.GetVirtualSize().cx;
  2305. ar << (int)2 << (int)m_editor.GetVirtualSize().cy;
  2306. ar << (int)3 << (int)m_editor.GetGridSize().cx;
  2307. ar << (int)4 << (int)m_editor.GetGridSize().cy;
  2308. ar << (int)5 << (int)m_nMarginLeft;
  2309. ar << (int)6 << (int)m_nMarginTop;
  2310. ar << (int)7 << (int)m_nMarginBottom;
  2311. ar << (int)8 << (int)m_nMarginRight;
  2312. nParanum = 16;//以下参数的数量
  2313. ar << nParanum;//先保存参数数量
  2314. ar << (UINT)m_SelTools.size();
  2315. for (UINT i = 0; i < m_SelTools.size(); i++)
  2316. {
  2317. TOOL& tool = m_SelTools[i];
  2318. // 版本
  2319. ar << (int)1 << tool.strVersion;
  2320. // 名称
  2321. ar << (int)2 << tool.strName;
  2322. // 显示名称
  2323. ar << (int)3 << tool.strShowName;
  2324. // dll路径
  2325. ar << (int)4 << tool.strDll;
  2326. // 是否展开
  2327. ar << (int)5 << tool.bIsExpand;
  2328. // 是否启用
  2329. ar << (int)6 << tool.bEnable;
  2330. //
  2331. ar << (int)7 << (int)tool.Type;
  2332. // 区域
  2333. ar << (int)8 << tool.rect;
  2334. ar << (int)9 << tool.strLinkName;
  2335. ar << (int)10 << tool.nInSleep;
  2336. ar << (int)11 << tool.nOutSleep;
  2337. ar << (int)12 << tool.strInfo;
  2338. ar << (int)13 << tool.hNextTool.nToolID;
  2339. ar << (int)14 << tool.hNextTool.strName;
  2340. ar << (int)15 << tool.hNextTool.strShowName;
  2341. ar << (int)16 << tool.nUseCount;
  2342. //////////////////////////////////////////////////////////////////////////
  2343. int nParanum_Inf = 9;
  2344. ar << nParanum_Inf;//先保存参数数量
  2345. ar << (UINT)tool.Interfaces.size();
  2346. for (UINT i = 0; i < tool.Interfaces.size(); i++)
  2347. {
  2348. TOOL_INTERFACE inf = tool.Interfaces[i];
  2349. ar << (int)1 << inf.strParentName;
  2350. ar << (int)2 << inf.bShow;
  2351. ar << (int)3 << inf.strName;
  2352. ar << (int)4 << (int)inf.VarType;
  2353. ar << (int)5 << (int)inf.InfDirection;
  2354. ar << (int)6 << inf.rect;
  2355. ar << (int)7 << (int)inf.InfType;
  2356. ar << (int)8 << (int)inf.InfWay;
  2357. ar << (int)9 << inf.nUseCount;
  2358. }
  2359. }
  2360. // 保存link
  2361. nParanum = 15;//以下参数的数量
  2362. ar << nParanum;//先保存参数数量
  2363. ar << (UINT)m_Links.size();
  2364. LINK_MAP::iterator iter;
  2365. for (iter = m_Links.begin(); iter != m_Links.end(); iter++)
  2366. {
  2367. ar << (int)1 << iter->source.strParentName;
  2368. ar << (int)2 << iter->source.nIndex;
  2369. ar << (int)3 << iter->dest.strParentName;
  2370. ar << (int)4 << iter->dest.nIndex;
  2371. ar << (int)5 << (int)iter->source.VarType;
  2372. ar << (int)6 << (int)iter->dest.VarType;
  2373. ar << (int)7 << iter->source.InfDirection;
  2374. ar << (int)8 << iter->dest.InfDirection;
  2375. ar << (int)9 << iter->source.strName;
  2376. ar << (int)10 << iter->dest.strName;
  2377. ar << (int)11 << (int)iter->source.InfType;
  2378. ar << (int)12 << (int)iter->dest.InfType;
  2379. ar << (int)13 << (int)iter->source.InfWay;
  2380. ar << (int)14 << (int)iter->dest.InfWay;
  2381. ar << (int)15 << (int)iter->bShow;
  2382. }
  2383. // 保存监控列表
  2384. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  2385. {
  2386. TOOL& tool = m_SelTools[i];
  2387. nParanum = 2;//以下参数的数量
  2388. ar << nParanum;//先保存参数数量
  2389. ar << (UINT)tool.Interfaces.size();
  2390. for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
  2391. {
  2392. TOOL_INTERFACE& inf = tool.Interfaces[j];
  2393. ar << (int)1 << inf.nIndex;
  2394. ar << (int)2 << inf.bMonitor;
  2395. }
  2396. }
  2397. return TRUE;
  2398. }
  2399. //////////////////////////////////////////////////
  2400. // 从文件中加载工具信息
  2401. BOOL CTaskWindow::LoadFromFile(CArchive& ar)
  2402. {
  2403. UINT nSize = 0;
  2404. vector<TOOL> newTools;
  2405. int nParanum = 0;//参数数量
  2406. int nPpara = 0;
  2407. //初始文件版本号从 101 开始添加,以前文件无版本号
  2408. if (g_nDocVersion > 101)
  2409. {
  2410. int m_nWindowHeight = 0;
  2411. int m_nWindowWidth = 0;
  2412. int m_gridHeight = 0;
  2413. int m_gridWidth = 0;
  2414. int m_marginLeft = 0;
  2415. int m_marginTop = 0;
  2416. int m_marginBottom = 0;
  2417. int m_marginRight = 0;
  2418. ar >> nParanum;
  2419. // 读取窗体信息
  2420. for (int i = 0; i < nParanum; i++)
  2421. {
  2422. ar >> nPpara;
  2423. switch (nPpara)
  2424. {
  2425. case 1: ar >> m_nWindowWidth; break;
  2426. case 2: ar >> m_nWindowHeight; break;
  2427. case 3: ar >> m_gridWidth; break;
  2428. case 4: ar >> m_gridHeight; break;
  2429. case 5: ar >> m_marginLeft; break;
  2430. case 6: ar >> m_marginTop; break;
  2431. case 7: ar >> m_marginBottom; break;
  2432. case 8: ar >> m_marginRight; break;
  2433. default:
  2434. CString strMsg;
  2435. strMsg.Format(_T("Task[%d] 加载失败!配置文档错误! "),m_nIndex);
  2436. USES_CONVERSION;
  2437. char * s_str = T2A(strMsg);
  2438. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2439. return FALSE;
  2440. }
  2441. }
  2442. m_editor.SetVirtualSize(CSize(m_nWindowWidth, m_nWindowHeight));
  2443. m_editor.SetGridSize(CSize(m_gridWidth, m_gridHeight));
  2444. m_editor.SetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom);
  2445. m_editor.RedrawWindow();
  2446. }
  2447. ar >> nParanum;//读取参数数量
  2448. ar >> nSize;
  2449. for (UINT i = 0; i < nSize; i++)
  2450. {
  2451. TOOL newTool;
  2452. for (int j = 0; j < nParanum; j++)
  2453. {
  2454. ar >> nPpara;
  2455. switch (nPpara)
  2456. {
  2457. case 1: ar >> newTool.strVersion; break;// 版本
  2458. case 2: ar >> newTool.strName; break;// 显示名称
  2459. case 3: ar >> newTool.strShowName; break;// 名称
  2460. case 4: ar >> newTool.strDll; break;// dll 路径
  2461. case 5: ar >> newTool.bIsExpand; break;// 是否展开
  2462. case 6: ar >> newTool.bEnable; break;// 是否启用
  2463. case 7: ar >> (int&)newTool.Type; break;// Type
  2464. case 8: ar >> newTool.rect; break;// 区域
  2465. case 9: ar >> newTool.strLinkName; break;//
  2466. case 10: ar >> newTool.nInSleep; break;//
  2467. case 11: ar >> newTool.nOutSleep; break;//
  2468. case 12: ar >> newTool.strInfo; break;//
  2469. case 13: ar >> newTool.hNextTool.nToolID; break;//
  2470. case 14: ar >> newTool.hNextTool.strName; break;//
  2471. case 15: ar >> newTool.hNextTool.strShowName; break;//
  2472. case 16:
  2473. {
  2474. if (g_nDocVersion > 106)
  2475. ar >> newTool.nUseCount;
  2476. else
  2477. ar >> (bool&)newTool.nUseCount;// 106之前,此变量为bool类型
  2478. }break;;//
  2479. default:
  2480. CString strMsg;
  2481. strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll);
  2482. //CUtility::CriticalBCGPMessageBox(strMsg);
  2483. OUTPUT_MSG msg;
  2484. msg.bWay = MSG_WAY::_ERROR;
  2485. msg.strMsg = strMsg;
  2486. USES_CONVERSION;
  2487. char * s_str = T2A(msg.strMsg);
  2488. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2489. return FALSE; break;
  2490. }
  2491. }
  2492. //初始文件版本号从 101 开始添加,以前文件无版本号
  2493. if (thePrefs.m_nDocHistoricVersion > 100)
  2494. {
  2495. if ((g_nDocVersion <= 105))// 106之前的版本
  2496. {
  2497. //////////////////////////////////////////////////////////////////////////
  2498. CString strType;
  2499. int nParanum_Inf = 0;
  2500. int nSize_Inf = 0;
  2501. ar >> nParanum_Inf;//读取参数数量
  2502. ar >> nSize_Inf;
  2503. for (int j = 0; j < nSize_Inf; j++)
  2504. {
  2505. TOOL_INTERFACE inf;
  2506. for (int k = 0; k < nParanum_Inf; k++)
  2507. {
  2508. ar >> nPpara;
  2509. switch (nPpara)
  2510. {
  2511. case 1: ar >> inf.strParentName; break;
  2512. case 2: ar >> inf.bShow; break;//
  2513. case 3: ar >> inf.strName; break;//
  2514. case 4: ar >> strType; break;//
  2515. case 5: ar >> (int&)inf.InfDirection; break;//
  2516. case 6: ar >> inf.rect; break;//
  2517. case 7: ar >> (int&)inf.InfType; break;//
  2518. case 8: ar >> (int&)inf.InfWay; break;//
  2519. default:
  2520. CString strMsg;
  2521. strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll);
  2522. USES_CONVERSION;
  2523. char * s_str = T2A(strMsg);
  2524. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2525. return FALSE;
  2526. }
  2527. }
  2528. if (strType == _T("int"))
  2529. {
  2530. inf.VarType = VAR_TYPE::Int_Var;
  2531. }
  2532. else if (strType == _T("CString"))
  2533. {
  2534. inf.VarType = VAR_TYPE::CString_Var;
  2535. }
  2536. else if (strType == _T("HImage"))
  2537. {
  2538. inf.VarType = VAR_TYPE::HImage_Var;
  2539. }
  2540. newTool.Interfaces.push_back(inf);
  2541. }
  2542. }
  2543. if (g_nDocVersion > 105)// 105之后的版本
  2544. {
  2545. //////////////////////////////////////////////////////////////////////////
  2546. int nParanum_Inf = 0;
  2547. int nSize_Inf = 0;
  2548. ar >> nParanum_Inf;//读取参数数量
  2549. ar >> nSize_Inf;
  2550. for (int j = 0; j < nSize_Inf; j++)
  2551. {
  2552. TOOL_INTERFACE inf;
  2553. for (int k = 0; k < nParanum_Inf; k++)
  2554. {
  2555. ar >> nPpara;
  2556. switch (nPpara)
  2557. {
  2558. case 1: ar >> inf.strParentName; break;
  2559. case 2: ar >> inf.bShow; break;//
  2560. case 3: ar >> inf.strName; break;//
  2561. case 4: ar >> (int&)inf.VarType; break;//
  2562. case 5: ar >> (int&)inf.InfDirection; break;//
  2563. case 6: ar >> inf.rect; break;//
  2564. case 7: ar >> (int&)inf.InfType; break;//
  2565. case 8: ar >> (int&)inf.InfWay; break;//
  2566. case 9: ar >> inf.nUseCount; break;//
  2567. default:
  2568. CString strMsg;
  2569. strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll);
  2570. USES_CONVERSION;
  2571. char * s_str = T2A(strMsg);
  2572. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2573. return FALSE;
  2574. }
  2575. }
  2576. newTool.Interfaces.push_back(inf);
  2577. }
  2578. }
  2579. }
  2580. // 首先校验工具版本号以及存在与否
  2581. // if (!g_pToolManager->ValidateTool(newTool))
  2582. // {
  2583. // return FALSE;
  2584. // }
  2585. if (newTool.rect.IsRectEmpty())
  2586. {
  2587. CPoint pt;
  2588. pt.x = 25 * i + 1;
  2589. pt.y = 25 * i + 1;
  2590. CRect rect(pt.x, pt.y, pt.x + 100, pt.y + 100);
  2591. newTool.rect = rect;
  2592. }
  2593. newTools.push_back(newTool);
  2594. }
  2595. // 如果校验通过,则添加工具
  2596. for (UINT i = 0; i < newTools.size(); i++)
  2597. {
  2598. if (!AddNewTools(newTools[i]))
  2599. {
  2600. CString strMsg;
  2601. strMsg.Format(_T("Task[%d] 在工具箱里未找到工具 %s ! "),m_nIndex, newTools[i].strName);
  2602. USES_CONVERSION;
  2603. char * s_str = T2A(strMsg);
  2604. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2605. return FALSE;
  2606. }
  2607. // 2018.10.16增加,手工调用Update
  2608. // 否则当前未激活的任务栏由于界面没有刷新,所以不会自动更新SelTool信息
  2609. UpdateTools( true );
  2610. if (newTools[i].Type == TOOL_TYPE::TOOL_BY_PROT)
  2611. {
  2612. for (size_t j = 0; j < newTools[i].Interfaces.size(); j++)
  2613. {
  2614. TOOL_INTERFACE newInf = newTools[i].Interfaces[j];
  2615. TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j];
  2616. inf.bShow = newInf.bShow;
  2617. inf.rect = newInf.rect;
  2618. }
  2619. }
  2620. m_SelTools[i].nInSleep = newTools[i].nInSleep;
  2621. m_SelTools[i].nOutSleep = newTools[i].nOutSleep;
  2622. m_SelTools[i].hNextTool = newTools[i].hNextTool;
  2623. UpdateTools( true);
  2624. }
  2625. if (g_nDocVersion > 105)
  2626. {
  2627. // 加载link
  2628. nParanum = 0;//参数数量
  2629. nSize = 0;
  2630. m_Links.clear();
  2631. nSize = 0;
  2632. //LINK newLink;
  2633. ar >> nParanum;//读取参数数量
  2634. ar >> nSize;
  2635. for (UINT i = 0; i < nSize; i++)
  2636. {
  2637. TOOL_INTERFACE source; // 连接的起点
  2638. TOOL_INTERFACE dest; // 连接的终点
  2639. bool bShow = true;
  2640. for (int i = 0; i < nParanum; i++)
  2641. {
  2642. nPpara = 0;
  2643. ar >> nPpara;
  2644. switch (nPpara)
  2645. {
  2646. case 1: ar >> source.strParentName; break;//
  2647. case 2: ar >> source.nIndex; break;//
  2648. case 3: ar >> dest.strParentName; break;//
  2649. case 4: ar >> dest.nIndex; break;//
  2650. case 5: ar >> (int&)source.VarType; break;//
  2651. case 6: ar >> (int&)dest.VarType; break;//
  2652. case 7: ar >> (int&)source.InfDirection; break;//
  2653. case 8: ar >> (int&)dest.InfDirection; break;//
  2654. case 9: ar >> source.strName; break;//
  2655. case 10: ar >> dest.strName; break;//
  2656. case 11: ar >> (int&)source.InfType; break;//
  2657. case 12: ar >> (int&)dest.InfType; break;//
  2658. case 13: ar >> (int&)source.InfWay; break;//
  2659. case 14: ar >> (int&)dest.InfWay; break;//
  2660. case 15: ar >> (int&)bShow; break;//
  2661. default:
  2662. CString strMsg;
  2663. strMsg.Format(_T("Task[%d] 加载工具连接信息失败!配置文档错误!"),m_nIndex );
  2664. USES_CONVERSION;
  2665. char * s_str = T2A(strMsg);
  2666. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2667. return FALSE;
  2668. }
  2669. }
  2670. TOOL_INTERFACE* pS = GetInterfaceByInterface(source);
  2671. TOOL_INTERFACE* pD = GetInterfaceByInterface(dest);
  2672. BOOL bStatus = FALSE;
  2673. if (pS != NULL &&
  2674. pD != NULL &&
  2675. (source.InfDirection == INF_DIRECTION::INF_OUT || source.InfDirection == INF_DIRECTION::INF_INOUT) &&
  2676. dest.InfDirection == INF_DIRECTION::INF_IN &&
  2677. source.VarType == dest.VarType)
  2678. {
  2679. bStatus = MakeLink(source, dest, bShow);
  2680. }
  2681. if (!bStatus)
  2682. {
  2683. CString strMsg;
  2684. strMsg.Format(_T("Task[%d] 加载工具连接信息失败%s.%s ----->>>>> %s.%s 参数不匹配 !"),m_nIndex, source.strParentName, source.strName, dest.strParentName, dest.strName); USES_CONVERSION;
  2685. char * s_str = T2A(strMsg);
  2686. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2687. }
  2688. }
  2689. }
  2690. else
  2691. {
  2692. // 加载link
  2693. nParanum = 0;//参数数量
  2694. nSize = 0;
  2695. m_Links.clear();
  2696. nSize = 0;
  2697. //LINK newLink;
  2698. CString strType;
  2699. ar >> nParanum;//读取参数数量
  2700. ar >> nSize;
  2701. for (UINT i = 0; i < nSize; i++)
  2702. {
  2703. TOOL_INTERFACE source; // 连接的起点
  2704. TOOL_INTERFACE dest; // 连接的终点
  2705. for (int i = 0; i < nParanum; i++)
  2706. {
  2707. nPpara = 0;
  2708. ar >> nPpara;
  2709. switch (nPpara)
  2710. {
  2711. case 1: ar >> source.strParentName; break;//
  2712. case 2: ar >> source.nIndex; break;//
  2713. case 3: ar >> dest.strParentName; break;//
  2714. case 4: ar >> dest.nIndex; break;//
  2715. case 5: ar >> strType; break;//
  2716. case 6: ar >> strType; break;//
  2717. case 7: ar >> (int&)source.InfDirection; break;//
  2718. case 8: ar >> (int&)dest.InfDirection; break;//
  2719. case 9: ar >> source.strName; break;//
  2720. case 10: ar >> dest.strName; break;//
  2721. case 11: ar >> (int&)source.InfType; break;//
  2722. case 12: ar >> (int&)dest.InfType; break;//
  2723. case 13: ar >> (int&)source.InfWay; break;//
  2724. case 14: ar >> (int&)dest.InfWay; break;//
  2725. default:
  2726. CString strMsg;
  2727. strMsg.Format(_T("Task[%d] 加载工具连接信息失败!配置文档错误!"),m_nIndex);
  2728. //CUtility::CriticalBCGPMessageBox(strMsg);
  2729. OUTPUT_MSG msg;
  2730. msg.bWay = MSG_WAY::_ERROR;
  2731. msg.strMsg = strMsg;
  2732. USES_CONVERSION;
  2733. char * s_str = T2A(msg.strMsg);
  2734. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2735. return FALSE;
  2736. }
  2737. }
  2738. TOOL_INTERFACE* pS = GetInterfaceByInterface(source);
  2739. TOOL_INTERFACE* pD = GetInterfaceByInterface(dest);
  2740. BOOL bStatus = FALSE;
  2741. if (pS != NULL &&
  2742. pD != NULL &&
  2743. source.InfDirection == INF_DIRECTION::INF_OUT &&
  2744. dest.InfDirection == INF_DIRECTION::INF_IN &&
  2745. source.VarType == dest.VarType)
  2746. {
  2747. bStatus = AddLink(source, dest, true);
  2748. }
  2749. if (!bStatus)
  2750. {
  2751. CString strMsg;
  2752. strMsg.Format(_T("Task[%d] 加载工具连接信息失败%s.%s ----->>>>> %s.%s 参数不匹配 !"),m_nIndex, source.strParentName, source.strName, dest.strParentName, dest.strName);
  2753. OUTPUT_MSG msg;
  2754. msg.bWay = MSG_WAY::_ERROR;
  2755. msg.strMsg = strMsg;
  2756. USES_CONVERSION;
  2757. char * s_str = T2A(msg.strMsg);
  2758. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2759. }
  2760. }
  2761. }
  2762. // 加载监控列表
  2763. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  2764. {
  2765. nParanum = 0;//参数数量
  2766. nSize = 0;
  2767. TOOL& tool = m_SelTools[i];
  2768. ar >> nParanum;//读取参数数量
  2769. ar >> nSize;
  2770. for (unsigned int j = 0; j < nSize; j++)
  2771. {
  2772. for (int i = 0; i < nParanum; i++)
  2773. {
  2774. nPpara = 0;
  2775. TOOL_INTERFACE tmpInf;
  2776. TOOL_INTERFACE& inf = tmpInf;
  2777. if (nSize == tool.Interfaces.size())
  2778. {
  2779. inf = tool.Interfaces[j];
  2780. }
  2781. ar >> nPpara;
  2782. switch (nPpara)
  2783. {
  2784. case 1: ar >> inf.nIndex; break;//
  2785. case 2: ar >> inf.bMonitor;; break;//
  2786. default:
  2787. CString strMsg;
  2788. strMsg.Format(_T("Task[%d] 加载工具监控信息失败!配置文档错误!"),m_nIndex);
  2789. OUTPUT_MSG msg;
  2790. msg.bWay = MSG_WAY::_ERROR;
  2791. msg.strMsg = strMsg;
  2792. USES_CONVERSION;
  2793. char * s_str = T2A(msg.strMsg);
  2794. g_Logger.Error(0, __FILE__, __LINE__, s_str);
  2795. return FALSE;;
  2796. }
  2797. }
  2798. }
  2799. }
  2800. UpdateTools( true);
  2801. return TRUE;
  2802. }
  2803. //////////////////////////////////////////////////////
  2804. // 当窗体激活时触发,变更当前工作窗体
  2805. void CTaskWindow::OnSetFocus(CWnd* pOldWnd)
  2806. {
  2807. CBCGPStatic::OnSetFocus(pOldWnd);
  2808. g_pTaskView->SetActiveTaskWindow(this, m_nIndex);
  2809. }
  2810. ///////////////////////////////////////////////////////
  2811. // 重置所有工具执行状态
  2812. void CTaskWindow::ResetToolExecCode()
  2813. {
  2814. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  2815. {
  2816. m_SelTools[i].nExecCode = RT_NONE;
  2817. }
  2818. }
  2819. //设置接收 工具状态 数据回调函数
  2820. void CTaskWindow::ToolStateCallback(CString strToolName, int nState, long long userParam)
  2821. {
  2822. CTaskWindow *pParam = (CTaskWindow*)(userParam);
  2823. if (pParam != NULL)
  2824. {
  2825. pParam->OnUpdateToolState(strToolName, nState);
  2826. }
  2827. }
  2828. ///////////////////////////////////////////////////////
  2829. // Tool Log 回调
  2830. void CTaskWindow::ToolLogCallback(CString strToolName, MSG_WAY nType, CString strMassage, long long userParam)
  2831. {
  2832. CMainFrame *pParam = (CMainFrame*)(userParam);
  2833. if (pParam != NULL)
  2834. {
  2835. OUTPUT_MSG msg;
  2836. msg.bWay = nType;
  2837. msg.strMsg = strToolName + _T(" ") + strMassage;
  2838. // pParam->ShowOutputInfo(msg, LOG);
  2839. USES_CONVERSION;
  2840. char * s_str = T2A(msg.strMsg);
  2841. switch (nType)
  2842. {
  2843. case MSG_WAY::_INFO:
  2844. g_Logger.Info(1, __FILE__, __LINE__, s_str);
  2845. break;
  2846. case MSG_WAY::_WARNING:
  2847. g_Logger.Warn(1, __FILE__, __LINE__, s_str);
  2848. break;
  2849. case MSG_WAY::_ERROR:
  2850. g_Logger.Error(1, __FILE__, __LINE__, s_str);
  2851. break;
  2852. default:
  2853. g_Logger.Error(1, __FILE__, __LINE__, s_str);
  2854. break;
  2855. break;
  2856. }
  2857. }
  2858. }
  2859. ///////////////////////////////////////////////////////
  2860. // Tool OnExecute 回调
  2861. void CTaskWindow::ToolOnExecuteCallback(CString strToolName, long long userParam)
  2862. {
  2863. CTaskWindow *pParam = (CTaskWindow*)(userParam);
  2864. if (pParam != NULL)
  2865. {
  2866. if (!strToolName.IsEmpty())
  2867. {
  2868. pParam->OnExecuteTool(strToolName);
  2869. }
  2870. }
  2871. }
  2872. ///////////////////////////////////////////////////////
  2873. // ToolBusy 回调
  2874. void CTaskWindow::ToolBusyCallback(CString strToolName, int nState, CString strMassage, long long userParam)
  2875. {
  2876. CTaskWindow *pParam = (CTaskWindow*)(userParam);
  2877. if (pParam != NULL)
  2878. {
  2879. if (!strToolName.IsEmpty())
  2880. {
  2881. }
  2882. }
  2883. }
  2884. //////////////////////////////////////////////////////////////
  2885. // 清空Watch
  2886. void CTaskWindow::WatchClear()
  2887. {
  2888. WATCH::iterator it = mWatch.begin();
  2889. for (; it != mWatch.end(); it++)
  2890. {
  2891. if (it->second != NULL)
  2892. {
  2893. it->second->DestroyWindow();
  2894. RELEASE_BUFFER(it->second);
  2895. }
  2896. }
  2897. mWatch.clear();
  2898. }
  2899. /////////////////////////////////////////////////////////
  2900. // 更新工具状态
  2901. void CTaskWindow::OnUpdateToolState(CString strToolName, int nState)
  2902. {
  2903. // 重置所有工具执行状态
  2904. ResetToolExecCode();
  2905. // 查找工具
  2906. for (unsigned int i = 0; i < m_SelTools.size(); i++)
  2907. {
  2908. TOOL& tool = m_SelTools[i];
  2909. if (tool.strShowName == strToolName)
  2910. {
  2911. tool.nToolState = nState;
  2912. //m_wndTree.Invalidate(TRUE);
  2913. }
  2914. }
  2915. }
  2916. void CTaskWindow::OnUpdate(CCmdUI* pCmdUI)
  2917. {
  2918. if (g_nRunningState != 0)
  2919. {
  2920. //g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("运行中,禁止该操作....."));
  2921. pCmdUI->Enable(false);
  2922. return;
  2923. }
  2924. pCmdUI->Enable(true);
  2925. }
  2926. void CTaskWindow::OnBnClickedUp()
  2927. {
  2928. m_editor.Down();
  2929. UpdateTools();
  2930. m_editor.RedrawWindow();
  2931. }
  2932. void CTaskWindow::OnBnClickedDown()
  2933. {
  2934. m_editor.Up();
  2935. UpdateTools();
  2936. m_editor.RedrawWindow();
  2937. }
  2938. void CTaskWindow::OnBnClickedFront()
  2939. {
  2940. m_editor.Bottom();
  2941. UpdateTools();
  2942. m_editor.RedrawWindow();
  2943. }
  2944. void CTaskWindow::OnBnClickedBottom()
  2945. {
  2946. m_editor.Front();
  2947. UpdateTools();
  2948. m_editor.RedrawWindow();
  2949. }
  2950. void CTaskWindow::OnBnClickedLeftAlign()
  2951. {
  2952. m_editor.LeftAlignSelected();
  2953. UpdateTools();
  2954. m_editor.RedrawWindow();
  2955. }
  2956. void CTaskWindow::OnBnClickedRightAlign()
  2957. {
  2958. m_editor.RightAlignSelected();
  2959. UpdateTools();
  2960. m_editor.RedrawWindow();
  2961. }
  2962. void CTaskWindow::OnBnClickedTopAlign()
  2963. {
  2964. m_editor.TopAlignSelected();
  2965. UpdateTools();
  2966. m_editor.RedrawWindow();
  2967. }
  2968. void CTaskWindow::OnBnClickedBottomAlign()
  2969. {
  2970. m_editor.BottomAlignSelected();
  2971. UpdateTools();
  2972. m_editor.RedrawWindow();
  2973. }
  2974. void CTaskWindow::OnBnClickedZoomIn()
  2975. {
  2976. // m_editor.SetZoom(m_editor.GetZoom() + m_editor.GetZoomFactor() * 10);
  2977. }
  2978. void CTaskWindow::OnBnClickedZoomOut()
  2979. {
  2980. // m_editor.SetZoom(m_editor.GetZoom() - m_editor.GetZoomFactor() * 10);
  2981. }
  2982. void CTaskWindow::OnBnClickedZoomZero()
  2983. {
  2984. m_editor.SetZoom(1.0);
  2985. m_editor.RedrawWindow();
  2986. }
  2987. void CTaskWindow::OnBnClickedSettings()
  2988. {
  2989. CString str;
  2990. this->GetWindowText(str);
  2991. CTaskSettings dlg;
  2992. dlg.m_TaskInfo.bTaskMode = m_TaskMode;
  2993. dlg.m_TaskInfo.nSleepTime = m_nSleepTime;
  2994. dlg.m_TaskInfo.strTaskName = m_strTaskName;
  2995. dlg.m_nWindowWidth = m_editor.GetVirtualSize().cx;
  2996. dlg.m_nWindowHeight = m_editor.GetVirtualSize().cy;
  2997. dlg.m_gridWidth = m_editor.GetGridSize().cx;
  2998. dlg.m_gridHeight = m_editor.GetGridSize().cy;
  2999. m_editor.GetMargins(dlg.m_marginLeft, dlg.m_marginTop, dlg.m_marginRight, dlg.m_marginBottom);
  3000. dlg.m_pTaskWindow = (LPVOID)this;
  3001. if (dlg.DoModal() == IDOK)
  3002. {
  3003. m_TaskMode = dlg.m_TaskInfo.bTaskMode;
  3004. m_nSleepTime = dlg.m_TaskInfo.nSleepTime;
  3005. m_strTaskName = dlg.m_TaskInfo.strTaskName;
  3006. m_editor.SetGridSize(CSize(dlg.m_gridWidth, dlg.m_gridHeight));
  3007. m_editor.SetVirtualSize(CSize(dlg.m_nWindowWidth, dlg.m_nWindowHeight));
  3008. m_editor.SetMargins(dlg.m_marginLeft, dlg.m_marginTop, dlg.m_marginRight, dlg.m_marginBottom);
  3009. m_editor.RedrawWindow();
  3010. //保存配置好的参数到本地
  3011. m_editor.GetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom);
  3012. g_pTaskView->SetTabText(m_nIndex, m_strTaskName);
  3013. }
  3014. UpdateTools();
  3015. m_editor.RedrawWindow();
  3016. }
  3017. void CTaskWindow::OnBnClickedRunOnce()
  3018. {
  3019. DWORD id;
  3020. HANDLE hTread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&CTaskWindow::SysRunOce, this, 0, &id);
  3021. CloseHandle(hTread);
  3022. }
  3023. void CTaskWindow::SysRunOce(LPVOID pParam)
  3024. {
  3025. CTaskWindow* pThis = (CTaskWindow*)pParam;
  3026. if (g_nRunningState != 0)
  3027. {
  3028. g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Error [State:%d]", g_nRunningState);
  3029. return;
  3030. }
  3031. g_nRunningState = 2;
  3032. // 清空当前任务栏中所有任务的执行状态
  3033. pThis->ResetToolExecCode();
  3034. SetEvent(pThis->m_hExecuteEven);
  3035. ResetEvent(pThis->m_hExecuteEven);
  3036. g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Start [%d]", g_nRunningState);
  3037. WaitForSingleObject(pThis->m_hDoneEven, INFINITE);
  3038. ResetEvent(pThis->m_hDoneEven);
  3039. g_nRunningState = 0;
  3040. g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Done [%d]", g_nRunningState);
  3041. }
  3042. void CTaskWindow::OnBnClickedButtonCopy()
  3043. {
  3044. // TODO: 在此添加控件通知处理程序代码
  3045. TOOL* pTool = this->GetToolByHandle(m_Item);
  3046. if (pTool != NULL)
  3047. {
  3048. CSharedFile memFile;
  3049. CArchive ar(&memFile, CArchive::store | CArchive::bNoFlushOnDelete);
  3050. ar << pTool->strName;
  3051. ar << pTool->strShowName;
  3052. pTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion);
  3053. ar << pTool->strName;
  3054. ar.Flush();
  3055. HGLOBAL hData = memFile.Detach();
  3056. if (OpenClipboard())
  3057. {
  3058. ::SetClipboardData(g_cfObjectFormat, hData);
  3059. CloseClipboard();
  3060. USES_CONVERSION;
  3061. CString str;
  3062. str.Format(_T("Task[%d] Cope %s Data OK "),m_nIndex, pTool->strShowName);
  3063. char * s_str = T2A(str);
  3064. g_Logger.Info(0, __FILE__, __LINE__, s_str);
  3065. }
  3066. }
  3067. }
  3068. void CTaskWindow::OnBnClickedButtonPaste()
  3069. {
  3070. // TODO: 在此添加控件通知处理程序代码
  3071. if (OpenClipboard())
  3072. {
  3073. HANDLE hData = ::GetClipboardData(g_cfObjectFormat);
  3074. if (hData != NULL)
  3075. {
  3076. //if (BCGPMessageBox(_T("是否粘贴数据 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Paste Data .....")) == IDYES)
  3077. {
  3078. CSharedFile memFile;
  3079. memFile.SetHandle(hData, FALSE);
  3080. CArchive ar(&memFile, CArchive::load);
  3081. CString str, strToolName, strShowName;
  3082. ar >> strToolName;
  3083. ar >> strShowName;
  3084. TOOL* pSourceTool = GetToolByShowName(strShowName);// 先择的模块(工具实体模块)
  3085. if (pSourceTool != NULL)
  3086. {
  3087. TOOL newTool;
  3088. newTool.strName = strToolName;
  3089. newTool.strShowName = strToolName/* + _T("Copy")*/;
  3090. newTool.rect = pSourceTool->rect;
  3091. newTool.rect.TopLeft().x += 10;
  3092. newTool.rect.TopLeft().y -= 30;
  3093. CString strShowName;
  3094. AddNewTools2(newTool, &strShowName);
  3095. UpdateTools();
  3096. TOOL* pNewTool = GetToolByShowName(strShowName);
  3097. if (pNewTool != NULL)
  3098. {
  3099. pNewTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion);
  3100. ar >> strToolName;
  3101. USES_CONVERSION;
  3102. str.Format(_T("Paste %s Data OK [%s]"), pNewTool->strShowName, strToolName);
  3103. char * s_str = T2A(str);
  3104. g_Logger.Info(0, __FILE__, __LINE__, s_str);
  3105. }
  3106. }
  3107. ar.Close();
  3108. memFile.Detach();
  3109. EmptyClipboard();// 清空粘贴板
  3110. }
  3111. }
  3112. CloseClipboard();
  3113. }
  3114. // TOOL* pTool = this->GetToolByHandle(m_Item);
  3115. // if (pTool != NULL)
  3116. // {
  3117. // if (OpenClipboard())
  3118. // {
  3119. // HANDLE hData = ::GetClipboardData(g_cfObjectFormat);
  3120. // if (hData != NULL)
  3121. // {
  3122. //
  3123. // CSharedFile memFile;
  3124. // memFile.SetHandle(hData, FALSE);
  3125. // CArchive ar(&memFile, CArchive::load);
  3126. // CString str, strToolName;
  3127. // ar >> strToolName;
  3128. // if (strToolName == pTool->strName)
  3129. // {
  3130. // if (BCGPMessageBox(_T("是否粘贴数据 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Paste Data .....")) == IDYES)
  3131. // {
  3132. // pTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion);
  3133. //
  3134. // ar >> strToolName;
  3135. //
  3136. // USES_CONVERSION;
  3137. // str.Format(_T("Paste %s Data OK [%s]"), pTool->strShowName , strToolName);
  3138. // char * s_str = T2A(str);
  3139. // g_Logger.Info(0, __FILE__, __LINE__, s_str);
  3140. // }
  3141. // }
  3142. // else
  3143. // {
  3144. // USES_CONVERSION;
  3145. // str.Format(_T("Paste %s Data Error SourceTool [%s]"), pTool->strShowName, strToolName);
  3146. // char * s_str = T2A(str);
  3147. // g_Logger.Error(0, __FILE__, __LINE__, s_str);
  3148. // }
  3149. // ar.Close();
  3150. // memFile.Detach();
  3151. // EmptyClipboard();// 清空粘贴板
  3152. // }
  3153. // else
  3154. // {
  3155. // USES_CONVERSION;
  3156. // CString str;
  3157. // str.Format(_T("Paste %s Data Error Dara isNULL"), pTool->strShowName);
  3158. // char * s_str = T2A(str);
  3159. // g_Logger.Error(0, __FILE__, __LINE__, s_str);
  3160. // }
  3161. // CloseClipboard();
  3162. // }
  3163. // }
  3164. }
  3165. void CTaskWindow::SortProtToolID(const TOOL* pSourceTool, const TOOL* pDestTool)
  3166. {
  3167. if (pDestTool != NULL && pSourceTool != NULL)
  3168. {
  3169. CDiagramEntityContainer* objs = static_cast<CDiagramEntityContainer*> (m_editor.GetDiagramEntityContainer());
  3170. if (objs)
  3171. {
  3172. UINT nIndex = 0;
  3173. for (UINT i = 0; i < objs->GetSize(); i++)
  3174. {
  3175. CFunctionBlock* obj = (CFunctionBlock*)objs->GetAt(i);
  3176. if (obj->Tools.strShowName == pSourceTool->strShowName)
  3177. {
  3178. m_editor.SetSelectedObject(obj);
  3179. }
  3180. }
  3181. }
  3182. {
  3183. int nToolID = pDestTool->nToolID;
  3184. int nProtID = pSourceTool->nToolID;
  3185. if (nProtID > nToolID)
  3186. {
  3187. for (int j = 0; j < (nProtID - nToolID); j++)
  3188. {
  3189. OnBnClickedUp();
  3190. }
  3191. }
  3192. }
  3193. }
  3194. }
  3195. void CTaskWindow::ShowNodeWatch(/*const*/ TOOL_INTERFACE* pInf)
  3196. {
  3197. if ( pInf != NULL )
  3198. {
  3199. WATCH::iterator it = mWatch.begin();
  3200. //先遍历,看该节点是否创建过
  3201. BOOL bFind = FALSE;
  3202. for (; it != mWatch.end(); )
  3203. {
  3204. if (it->first == pInf)
  3205. {
  3206. bFind = TRUE;
  3207. break;
  3208. }
  3209. ++it;
  3210. }
  3211. if (!bFind)
  3212. {
  3213. CNodeWatchDlg* pDlg = NULL;
  3214. pDlg = new CNodeWatchDlg(this);
  3215. pDlg->Create(IDD_NODEWATCHDLG, g_pMainFrame->GetActiveView());
  3216. pDlg->strName = pInf->strName;
  3217. pDlg->strParentName = pInf->strParentName;
  3218. mWatch[pInf] = pDlg;
  3219. }
  3220. if (mWatch[pInf] != NULL)
  3221. {
  3222. mWatch[pInf]->ShowWindow(SW_SHOW);
  3223. CString str;
  3224. str.Format(_T("监视:%s [ %s ]"), pInf->strParentName, pInf->strName);
  3225. mWatch[pInf]->SetWindowTextW(str);
  3226. }
  3227. }
  3228. }