123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942 |
- // workspace2.cpp : implementation of the CWorkSpaceBar2 class
- //
- #include "stdafx.h"
- #include "VisionPlus.h"
- #include "TaskWindow.h"
- #include "ToolWindow.h"
- #include "MainFrm.h"
- #include "GlobalSetting.h"
- #include "Utility.h"
- #include "ToolRenameDlg.h"
- #include "NodeWatchDlg.h"
- #include "Preferences.h"
- #include "TaskSettings.h"
- #include "Draw\DialogLink.h"
- #include "Draw\DialogLink.h"
- #include "HWindow.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- const int nBorderSize = 1;
- #define HTBUTTON_CUSTOM_1 HTHELP + 12
- #define HTBUTTON_CUSTOM_2 HTHELP + 13
- #define HTBUTTON_CUSTOM_3 HTHELP + 14
- // 绘制相关的参数
- #define COLOR_BLUE RGB(0,0,255)
- #define COLOR_BLUE_TEST RGB(255,0,0)
- #define LINK_WIDTH 1
- #define LINK_WIDTH_BOLD 3
- #define ARROW_LENGTH 5 // 箭头长度
- extern UINT Process(LPVOID lpParam);
- /////////////////////////////////////////////////////////////////////////////
- // CWorkSpaceBar2
- IMPLEMENT_DYNAMIC(CTaskWindow, CBCGPStatic)
- BEGIN_MESSAGE_MAP(CTaskWindow, CBCGPStatic)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_WM_PAINT()
- ON_WM_LBUTTONDOWN()
- ON_WM_CONTEXTMENU()
- ON_WM_SETFOCUS()
- ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_IN, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_OUT, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_ZOOM_NULL, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_SETTINGS, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_SNAP_TO_GRID, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_LEFT_ALIGN, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_RIGHT_ALIGN, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_TOP_ALIGN, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_BOTTOM_ALIGN, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_UP, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_FRONT, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_DOWN, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_BOTTOM, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_MAKE_SAME_SIZE, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_DRAW_DELETE, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_TASK_SETTING, OnUpdate)
- ON_UPDATE_COMMAND_UI(IDC_TASK_RUNONCE, OnUpdate)
- ON_BN_CLICKED(IDC_DRAW_UP, &CTaskWindow::OnBnClickedUp)
- ON_BN_CLICKED(IDC_DRAW_DOWN, &CTaskWindow::OnBnClickedDown)
- ON_BN_CLICKED(IDC_DRAW_FRONT, &CTaskWindow::OnBnClickedFront)
- ON_BN_CLICKED(IDC_DRAW_BOTTOM, &CTaskWindow::OnBnClickedBottom)
- ON_BN_CLICKED(IDC_DRAW_LEFT_ALIGN, &CTaskWindow::OnBnClickedLeftAlign)
- ON_BN_CLICKED(IDC_DRAW_RIGHT_ALIGN, &CTaskWindow::OnBnClickedRightAlign)
- ON_BN_CLICKED(IDC_DRAW_TOP_ALIGN, &CTaskWindow::OnBnClickedTopAlign)
- ON_BN_CLICKED(IDC_DRAW_BOTTOM_ALIGN, &CTaskWindow::OnBnClickedBottomAlign)
- ON_BN_CLICKED(IDC_DRAW_ZOOM_IN, &CTaskWindow::OnBnClickedZoomIn)
- ON_BN_CLICKED(IDC_DRAW_ZOOM_OUT, &CTaskWindow::OnBnClickedZoomOut)
- ON_BN_CLICKED(IDC_DRAW_ZOOM_NULL, &CTaskWindow::OnBnClickedZoomZero)
- ON_BN_CLICKED(IDC_TASK_SETTING, &CTaskWindow::OnBnClickedSettings)
- ON_BN_CLICKED(IDC_TASK_RUNONCE, &CTaskWindow::OnBnClickedRunOnce)
- END_MESSAGE_MAP()
- // void CTaskWindow::OnDraw(CDC* pDC)
- // {
- // CDocument* pDoc = GetDocument();
- // // TODO: 在此添加绘制代码
- // }
- // CTakView 诊断
- #ifdef _DEBUG
- void CTaskWindow::AssertValid() const
- {
- CBCGPStatic::AssertValid();
- }
- #ifndef _WIN32_WCE
- void CTaskWindow::Dump(CDumpContext& dc) const
- {
- CBCGPStatic::Dump(dc);
- }
- #endif
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CWorkSpaceBar2 construction/destruction
- CTaskWindow::CTaskWindow()
- {
- g_VatTypeMap.InitVarTypeMap();
- m_penLink.CreatePen(PS_SOLID, LINK_WIDTH, COLOR_BLUE);
- m_penLinkBold.CreatePen(PS_SOLID, LINK_WIDTH_BOLD, COLOR_BLUE);
- m_penLinkTest.CreatePen(PS_SOLID, LINK_WIDTH, COLOR_BLUE_TEST);
- g_pToolManager = CToolManager::GetInstance();
- m_TaskMode = TASK_MODE::MAIN_TASK;
- // 第一个参数, TRUE,需要手动复位。
- //第二个参数,默认状态初始状态,true,有信号,false无信号
- //(ResetEvent()恢复为无信号,无信号时会挂起)
- //如果设置为FALSE,当一个线程等待到事件信号后系统会自动将事件状态复原为无信号状态
- m_hExecuteEven = CreateEventW(NULL, TRUE, FALSE, NULL);
- // m_hBusyEven = CreateEventW(NULL, FALSE, TRUE, NULL);// 初始为有信号状态
- m_hDoneEven = CreateEventW(NULL, TRUE, FALSE, NULL);// 需要ResetEvent(),初始为有信号状态
- m_Links.clear();
- m_RunningTime = 0;
- m_dRunningCount = 0;
- m_hThread = NULL;
- m_nIndex = DEFAULT_TASK_WINDOW;
- m_bExitThread = false;
- m_nSleepTime = 1;
- m_ToolTip = NULL;
- m_nMarginLeft = 0;
- m_nMarginTop = 0;
- m_nMarginBottom = 0;
- m_nMarginRight = 0;
- }
- CTaskWindow::~CTaskWindow()
- {
- // m_SelTools.clear();
- // m_Links.clear();
- // m_TsetLinks.clear();
- // m_wndTree.DestroyWindow();
- //为了使线程退出
- m_bExitThread = true;
- SetEvent(m_hExecuteEven);
- SetEvent(m_hDoneEven);
- //// 2019-3-23 释放选择的工具
- //for (unsigned int i = 0; i < m_SelTools.size(); i++)
- //{
- // // 调用Release
- // if (m_SelTools[i].hDllTool)
- // {
- // // 调用Release接口
- // typedef void(*RELEASE)();
- // RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE);
- // if (Release)
- // {
- // Release();
- // }
- // FreeLibrary(m_SelTools[i].hDllTool);
- // }
- //}
- for (size_t i = 0; i < m_SelTools.size(); i++)
- {
- RELEASE_BUFFER(m_SelTools.at(i).pDllPtr);
- FreeLibrary(m_SelTools[i].hDllTool);
- }
- m_SelTools.clear();
- RELEASE_HANDLE(m_hExecuteEven);
- // RELEASE_HANDLE(m_hBusyEven);
- RELEASE_HANDLE(m_hDoneEven);
- RELEASE_BUFFER(m_ToolTip);
- // 绘图清理
- m_Bitmap[0].DeleteObject();
- m_Bitmap[1].DeleteObject();
- m_Bitmap[2].DeleteObject();
- WatchClear();
- m_wndToolBar.DestroyWindow();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWorkSpaceBar2 message handlers
- int CTaskWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CBCGPStatic::OnCreate(lpCreateStruct) == -1)
- return -1;
- CRect rectDummy;
- rectDummy.SetRectEmpty();
- // Create tree control:
- const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES |
- TVS_LINESATROOT | TVS_HASBUTTONS;
- // m_wndTree.m_bVisualManagerStyle = TRUE;
- //
- // if (!m_wndTree.Create(dwViewStyle, rectDummy, this, 1))
- // {
- // TRACE0("Failed to create workspace view\n");
- // return -1; // fail to create
- // }
- //CBCGPToolBar::AddToolBarForImageCollection(IDR_TASKFRAME, IDB_TASKTOOLS);
- // Create toolbar:
- m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
- CRect(1, 1, 1, 1), AFX_IDW_DIALOGBAR + 6 + m_nIndex);
- // 以上增加的数字 6 是在 3 个 MainFrm 中添加的ToolBarID (1-3),Draw中添加的ToolBar ID (4-5)
- // 如果不设置ID,会造成多个对象使用一个ID,异常现象为图标显示不正确
- //m_wndToolBar.SetControlVisualMode(this);
- m_wndToolBar.LoadToolBar(IDR_TASKFRAME, 0, 0, TRUE /* Locked bar */, 0, 0, IDB_TASKTOOLS);
- // m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
- // m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() &
- // ~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
- m_wndToolBar.SetOwner(this);
- // 所有命令都将通过此对话框而不是父框架进行路由:
- m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
- // 设置工具栏的名称
- m_wndToolBar.SetWindowText(m_strTaskName);
- GetClientRect(rectDummy);
- m_editor.Create(dwViewStyle, rectDummy, (CWnd*)this, NULL);
- //m_editor.SetVirtualSize(CSize(1800, 600));
- m_editor.SetModified(FALSE);
- m_editor.SetBackgroundColor(globalData.clrBarHilite);
- m_editor.SetSnapToGrid(FALSE);
- m_editor.SetRestraints(RESTRAINT_VIRTUAL);
- m_editor.ShowGrid(false);
- m_editor.GetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom);
- // 2018.10.16 更换了TaskWnd和TreeCtrl的绑定方式
- m_editor.m_pBindTaskWnd = this;
- m_Bitmap[0].LoadBitmap(IDB_BITMAP_INVALID);
- m_Bitmap[1].LoadBitmap(IDB_BITMAP_EERROR);
- m_Bitmap[2].LoadBitmap(IDB_BITMAP_OK);
- // Load caption icons:
- m_CaptionIcons.SetImageSize(CSize(24, 24));
- m_CaptionIcons.Load(IDR_CAPTION_ICONS);
- globalUtils.ScaleByDPI(m_CaptionIcons);
- m_ToolTip = new CCustomToolTipCtrl;
- m_ToolTip->CreateEx(this, TTS_ALWAYSTIP);
- m_ToolTip->Activate(TRUE);//使活跃
- CRect rect;
- m_editor.GetClientRect(&rect); //获取树控件的客户区矩形
- m_ToolTip->AddTool(CWnd::FromHandle(m_editor.m_hWnd), _T("我的树"));
- m_ToolTip->SetDelayTime(500);
- //
- m_hThread = AfxBeginThread(Process, this);
- ;
- //
- // // 2018.10.16 更换了TaskWnd和TreeCtrl的绑定方式
- //m_wndTree.m_pBindTaskWnd = this;
- return 0;
- }
- void CTaskWindow::OnSize(UINT nType, int cx, int cy)
- {
- CBCGPStatic::OnSize(nType, cx, cy);
- // Tree control should cover a whole client area:
- // m_wndTree.SetWindowPos(NULL, nBorderSize, nBorderSize,
- // cx - 2 * nBorderSize, cy - 2 * nBorderSize,
- // SWP_NOACTIVATE | SWP_NOZORDER);
- int nToobarHeidit = 25;
- if (m_wndToolBar.m_hWnd)
- {
- m_wndToolBar.SetWindowPos(NULL, 0, 0, cx, nToobarHeidit, SWP_NOACTIVATE | SWP_NOZORDER);
- }
- if (m_editor.m_hWnd)
- {
- m_editor.MoveWindow(0, nToobarHeidit, cx, cy - nToobarHeidit);
- m_editor.RedrawWindow();
- }
- }
- BOOL CTaskWindow::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message == WM_MOUSEMOVE)
- {
- CPoint pt = pMsg->pt;
- m_editor.ScreenToVirtual(pt);
- HTREEITEM item = m_editor.GetCursorItem();
- if (m_Item != item)
- {
- m_Item = item;
- if (item != NULL)
- {
- CString str;
- //TOOL_INTERFACE* pInf = this->GetInterfaceByHandle(item);
- TOOL* pTool = this->GetToolByHandle(item);
- if (pTool != NULL)
- {
- CString strName;
- CString strShowName;
- CString strAliasName;
- CString strStatus;
- CString strInfo;
- CString strEven;
- TOOL* pActiveTool = GetToolByHandle(item);
- if (pActiveTool != NULL && TOOL_ERROR == pActiveTool->nToolState)
- {
- strStatus = _T("工具状态:初始化错误!");
- }
- if (pActiveTool != NULL && TOOL_SUCCESS == pActiveTool->nToolState)
- {
- if (RT_ERROR == pActiveTool->nExecCode)
- {
- strStatus = _T("工具状态: 执行错误!");
- }
- else if (RT_TIMEOUT == pActiveTool->nExecCode)
- {
- strStatus = _T("工具状态: 执行超时!");
- }
- else if (RT_NONE == pActiveTool->nExecCode)
- {
- strStatus = _T("工具状态: 未执行!");
- }
- else if (RT_SUCCESS == pActiveTool->nExecCode)
- {
- strStatus = _T("工具状态: 执行正确!");
- }
- else if (RT_GOTO == pActiveTool->nExecCode)
- {
- strStatus = _T("工具状态: 执行跳转!");
- }
- else
- {
- strStatus = _T("工具状态: 未知状态!");
- }
- }
- CString strInSleep;
- if (pActiveTool->nInSleep > 0)
- {
- strInSleep.Format(_T("入口延时: %d ms\n"), pActiveTool->nInSleep);
- }
- CString strOutSleep;
- if (pActiveTool->nOutSleep > 0)
- {
- strOutSleep.Format(_T("出口延时: %d ms\n"), pActiveTool->nOutSleep);
- }
- if (pActiveTool->pDllPtr->m_Even.hEvenHandle != NULL)
- {
- strEven.Format(_T("触发模式: Even\n"));
- }
- strName.Format(_T("工具名称: %s \n"), pActiveTool->strName);
- strAliasName.Format(_T("工具别名: %s \n"), pActiveTool->strAliasName);
- strShowName.Format(_T("显示名称: %s \n"), pActiveTool->strShowName);
- strInfo.Format(_T("工具信息: %s \n"), pActiveTool->strInfo);
- str.Format(_T("%s%s%s%s%s%s%s%s"), strName, strAliasName, strShowName, strInSleep, strOutSleep, strEven, strInfo, strStatus);
- m_ToolTip->m_InterfaceDispType = INTERFACE_DISP_TYPE::IVDT_CSTRING;
- }
- else
- {
- m_ToolTip->m_hvObj.Clear();
- m_ToolTip->m_Image.Clear();
- //ClearWindow(m_ToolTip->m_HTWindow);
- CString strProtName;
- CString strProtType;
- CString strProtInfo;
- CString strProtVilue;
- TOOL_INTERFACE* pInf = GetInterfaceByHandle(item);
- if (pInf != NULL)
- {
- CString strValue;
- m_ToolTip->m_InterfaceDispType = UpdateUIValue(strValue, &m_ToolTip->m_Image, &m_ToolTip->m_hvObj, pInf);
- if (strValue.IsEmpty())
- {
- strValue = _T("NULL");
- }
- strProtName.Format(_T("ProtName: [ %s ]\n"), pInf->strName);
- strProtType.Format(_T("ProtType : [ %s ]\n"), g_VatTypeMap.GetVarTypeName(pInf->VarType));
- strProtInfo.Format(_T("ProtInfo : [ %s ]\n"), pInf->strInfo);
- strProtVilue.Format(_T(" __Vilue : [ %s ]"), strValue);
- }
- str.Format(_T("%s%s%s%s"), strProtName, strProtType, strProtInfo, strProtVilue);
- if (str.IsEmpty())
- {
- str = _T("NULL");
- }
- }
- m_ToolTip->UpdateTipText(str, CWnd::FromHandle(m_editor.m_hWnd));
- m_ToolTip->RelayEvent(pMsg);
- }
- }
- }
- if (pMsg->message == WM_KEYDOWN)
- {
- if (GetKeyState(VK_CONTROL) & 0x80)
- if (pMsg->wParam == 'c' || pMsg->wParam == 'C')
- {
- OnBnClickedButtonCopy();
- }
- if (pMsg->wParam == 'v' || pMsg->wParam == 'V')
- {
- OnBnClickedButtonPaste();
- }
- }
- return CBCGPStatic::PreTranslateMessage(pMsg);
- }
- void CTaskWindow::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- CRect rectTree;
- // m_wndTree.GetWindowRect(rectTree);
- // ScreenToClient(rectTree);
- //
- // rectTree.InflateRect(nBorderSize, nBorderSize);
- //
- GetClientRect(rectTree);
- dc.Draw3dRect(rectTree, globalData.clrBarShadow, globalData.clrBarShadow);
- // m_wndTree.SetBkColor(globalData.clrBarHilite);
- }
- ///////////////////////////////////////////////////
- // 从工具箱中添加新的工具到任务栏
- void CTaskWindow::AddNewTools(CString strToolName, HTREEITEM hPrevItem)
- {
- // 处理重名问题
- CString strToolShowName = strToolName;
- // // 遍历所有节点,查找是否有重名节点,并且找一下序号
- int nRepeat = 1;
- vector<CString> ShowNameLink;
- for (int i = 0; i < m_SelTools.size(); i++)
- {
- CString strName = m_SelTools[i].strName;
- CString strShow = m_SelTools[i].strShowName;
- if (strName.Find(strToolName) >= 0)
- {
- nRepeat++;
- ShowNameLink.push_back(strShow);
- }
- }
- // 生成界面中的名字
- if (nRepeat > 0)
- {
- strToolShowName.AppendFormat(_T(" %d"), nRepeat);
- int xxx = 0;
- for (int j = 0; j < ShowNameLink.size(); j++)
- {
- if (strToolShowName.Compare(ShowNameLink[j]) == 0)
- {
- xxx++;
- strToolShowName.AppendFormat(_T("-%d"), xxx);
- }
- }
- //strToolShowName.AppendFormat(_T(" %d"), nRepeat+1 );
- m_RenameList.insert(pair<CString, CString>(strToolShowName, strToolName));
- }
- // 依次将对应的工具信息添加到界面中
- for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++)
- {
- TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i];
- // 如果拖拽过来的是一个分类,则不处理
- if (cate.strName.Compare(strToolName) == 0)
- {
- return;
- }
- // 遍历本分类中的所有信息
- for (unsigned int j = 0; j < cate.Tools.size(); j++)
- {
- TOOL& tool = cate.Tools[j];
- // 如果找到了对应的工具
- if (tool.strName.Compare(strToolName) == 0 ||
- tool.strAliasName.Compare(strToolName) == 0
- )
- {
- // 则把本工具,以及下面的所有接口,都添加到界面中
- tool.strShowName = strToolShowName;
- CFunctionBlock* obj = new CFunctionBlock(tool, m_nIndex);
- CString strTitle;
- strTitle.Format(_T("%d"), m_SelTools.size());
- obj->SetTitle(strTitle);
- m_editor.StartDrawingObject(obj);
- this->UpdateTools();
- }
- }
- }
-
- CString str;
- str.Format(_T("Task[%d] Add:%s"), m_nIndex, strToolShowName);
- USES_CONVERSION;
- char * s_str = T2A(str);
- g_Logger.Info(0, __FILE__, __LINE__, s_str);;
- }
- ////////////////////////////////////////////////////////////////////
- // 从工具箱中添加新的工具到任务栏(用于反序列化使用)
- BOOL CTaskWindow::AddNewTools(const TOOL& newTool)
- {
- CDiagramEntityContainer* pContainer = m_editor.GetDiagramEntityContainer();
- // 如果两个名字不同,则需要加到重命名列表中
- if (newTool.strShowName.Compare(newTool.strName) != 0)
- {
- m_RenameList.insert(pair<CString, CString>(newTool.strShowName, newTool.strName));
- }
- // 依次将对应的工具信息添加到界面中
- for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++)
- {
- TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i];
- // 遍历本分类中的所有信息
- for (unsigned int j = 0; j < cate.Tools.size(); j++)
- {
- TOOL tool = cate.Tools[j];
- // 如果找到了对应的工具
- if (tool.strName.Compare(newTool.strName) == 0 ||
- tool.strAliasName.Compare(newTool.strName) == 0
- )
- {
- for (int k = 0; k < tool.Interfaces.size(); k++)
- {
- // 此处添加的判断,是为了应对工具端口的增加。
- if (k < newTool.Interfaces.size())
- {
- if (tool.Interfaces[k].VarType == (newTool.Interfaces[k].VarType))
- {
- bool bShow = newTool.Interfaces[k].bShow;
- tool.Interfaces[k].bShow = bShow;
- tool.Interfaces[k].nUseCount = newTool.Interfaces[k].nUseCount;
- }
- }
- }
- // 则把本工具,以及下面的所有接口,都添加到界面中
- CFunctionBlock* obj;
- obj = new CFunctionBlock(tool, m_nIndex);
- CString strTitle;
- strTitle.Format(_T("--%d"), m_SelTools.size());
- obj->SetTitle(strTitle);
- // 在此添加其它属性
- obj->Tools.strShowName = newTool.strShowName;
- obj->Tools.rect = newTool.rect;
- obj->Tools.strLinkName = newTool.strLinkName;
- obj->Tools.nInSleep = newTool.nInSleep;
- obj->Tools.nOutSleep = newTool.nOutSleep;
- obj->Tools.strInfo = newTool.strInfo;
- obj->Tools.nUseCount = newTool.nUseCount;
- obj->SetRect(newTool.rect);
- pContainer->Add(obj);
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- ////////////////////////////////////////////////////////////////////
- // 从工具箱中添加新的工具到任务栏
- BOOL CTaskWindow::AddNewTools2(const TOOL& newTool, CString* p_strShowName)
- {
- CDiagramEntityContainer* pContainer = m_editor.GetDiagramEntityContainer();
- CString strToolName = newTool.strShowName;
- // 处理重名问题
- CString strToolShowName = strToolName;
- // // 遍历所有节点,查找是否有重名节点,并且找一下序号
- int nRepeat = 1;
- vector<CString> ShowNameLink;
- for (int i = 0; i < m_SelTools.size(); i++)
- {
- CString strName = m_SelTools[i].strName;
- CString strShow = m_SelTools[i].strShowName;
- if (strName.Find(strToolName) >= 0)
- {
- nRepeat++;
- ShowNameLink.push_back(strShow);
- }
- }
- // 生成界面中的名字
- if (nRepeat > 0)
- {
- strToolShowName.AppendFormat(_T(" %d"), nRepeat);
- int xxx = 0;
- for (int j = 0; j < ShowNameLink.size(); j++)
- {
- if (strToolShowName.Compare(ShowNameLink[j]) == 0)
- {
- xxx++;
- strToolShowName.AppendFormat(_T("-%d"), xxx);
- }
- }
- //strToolShowName.AppendFormat(_T(" %d"), nRepeat+1 );
- m_RenameList.insert(pair<CString, CString>(strToolShowName, strToolName));
- }
- *p_strShowName = strToolShowName;
- // 依次将对应的工具信息添加到界面中
- for (unsigned int i = 0; i < g_pToolManager->m_TotalTools.size(); i++)
- {
- TOOL_CATEGORY cate = g_pToolManager->m_TotalTools[i];
- // 遍历本分类中的所有信息
- for (unsigned int j = 0; j < cate.Tools.size(); j++)
- {
- TOOL tool = cate.Tools[j];
- // 如果找到了对应的工具
- if (tool.strName.Compare(newTool.strName) == 0 ||
- tool.strAliasName.Compare(newTool.strName) == 0
- )
- {
-
- // 把本工具,以及下面的所有接口,都添加到界面中
- CFunctionBlock* obj;
- obj = new CFunctionBlock(tool, m_nIndex);
- CString strTitle;
- strTitle.Format(_T("--%d"), m_SelTools.size());
- obj->SetTitle(strTitle);
- // 在此添加其它属性
- obj->Tools.strShowName = strToolShowName;
- obj->Tools.rect = newTool.rect;
- obj->Tools.strLinkName = tool.strLinkName;
- obj->Tools.nInSleep = tool.nInSleep;
- obj->Tools.nOutSleep = tool.nOutSleep;
- obj->Tools.strInfo = tool.strInfo;
- obj->Tools.nUseCount = tool.nUseCount;
- obj->SetRect(newTool.rect);
- pContainer->Add(obj);
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- ////////////////////////////////////////////////////////////////////
- // 根据用户拖动的内容添加接口连线
- BOOL CTaskWindow::AddLink(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD)
- {
- TOOL_INTERFACE* pInfStart = NULL;
- TOOL_INTERFACE* pInfEnd = NULL;
- // 首先搜索到起点和终点
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
- {
- TOOL_INTERFACE inf = tool.Interfaces[j];
- if (inf.hHandle == m_hItemDragS)
- {
- pInfStart = &tool.Interfaces[j];
- pInfStart->nUseCount++;
- break;
- }
- else if (inf.hHandle == m_hItemDragD)
- {
- pInfEnd = &tool.Interfaces[j];
- pInfEnd->nUseCount++;
- break;
- }
- }
- }
- if (pInfStart == NULL || pInfEnd == NULL)
- {
- return FALSE;
- }
- // 建立关联
- MakeLink(*pInfStart, *pInfEnd);
- return TRUE;
- }
- ////////////////////////////////////////////////////////////////////
- // 根据用户拖动的内容添加接口连线
- BOOL CTaskWindow::AddLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest, bool bIsLoad)
- {
- TOOL_INTERFACE* pInfStart = NULL;
- TOOL_INTERFACE* pInfEnd = NULL;
- // 首先搜索到起点和终点
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
- {
- TOOL_INTERFACE inf = tool.Interfaces[j];
- if (inf == source/* && inf.InfDirection == INF_DIRECTION::INF_OUT && inf.strParentName != dest.strParentName*/)
- {
- pInfStart = &tool.Interfaces[source.nIndex - 1];
- if (!bIsLoad)
- pInfStart->nUseCount++;
- //break;
- }
- if (inf == dest /* && inf.InfDirection == INF_DIRECTION::INF_IN && inf.strParentName != source.strParentName*/)
- {
- pInfEnd = &tool.Interfaces[dest.nIndex - 1];
- if (!bIsLoad)
- pInfEnd->nUseCount++;
- //break;
- }
- }
- }
- if (pInfStart == NULL || pInfEnd == NULL)
- {
- if (pInfStart == NULL)
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] 找不到 %s.%s "),m_nIndex, source.strParentName, source.strName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- }
- if (pInfEnd == NULL)
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] 找不到 %s.%s "),m_nIndex, dest.strParentName, dest.strName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- }
- CString strMsg;
- strMsg.Format(_T("Task[%d] Make link Error: %s-%s to %s-%s"),m_nIndex,
- source.strParentName, source.strName,
- dest.strParentName, dest.strName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE;
- }
- if (pInfStart->strParentName == pInfEnd->strParentName)
- {
- return FALSE;
- }
- BOOL status = MakeLink(*pInfStart, *pInfEnd);// 建立关联
- return status;
- return TRUE;
- }
- ///////////////////////////////////////////////////////////////////////////
- // 根据用户拖动的内容添加接口连线
- BOOL CTaskWindow::AddTestLink(const HTREEITEM& m_hItemDragS, const HTREEITEM& m_hItemDragD)
- {
- TOOL_INTERFACE* pInfStart = NULL;
- TOOL_INTERFACE* pInfEnd = NULL;
- // 首先搜索到起点和终点
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
- {
- TOOL_INTERFACE inf = tool.Interfaces[j];
- if (inf.hHandle == m_hItemDragS)
- {
- pInfStart = &tool.Interfaces[j];
- break;
- }
- else if (inf.hHandle == m_hItemDragD)
- {
- pInfEnd = &tool.Interfaces[j];
- break;
- }
- }
- }
- if (pInfStart == NULL || pInfEnd == NULL)
- {
- return FALSE;
- }
- // 建立关联
- MakeTestLink(*pInfStart, *pInfEnd);
- return TRUE;
- }
- ///////////////////////////////////////////////////////////////////////////
- // 添加工具到任务栏的时候智能链接
- void CTaskWindow::SmartLink()
- {
- int nIndex = (int)m_SelTools.size() - 1;
- if (nIndex < 1)
- {
- return;
- }
- //获取最后一个添加的工具
- TOOL tool = m_SelTools[nIndex];
- for (unsigned int i = 0; i < tool.Interfaces.size(); i++)
- {
- const TOOL_INTERFACE& DestInf = tool.Interfaces[i];
- // 如果当前接口设置了不显示,则不显示该接口
- if ((DestInf.InfType == INF_VALUE_1 || DestInf.InfType == INF_VALUE_2 || DestInf.InfType == INF_VALUE_3 || DestInf.InfType == INF_VALUE_4)
- && (DestInf.InfDirection == INF_IN))
- {
- if (DestInf.bSmartLink && DestInf.bShow)
- {
- ToSmartLink(DestInf);
- }
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////////
- //通过输入的目标端口执行智能链接动作
- void CTaskWindow::ToSmartLink(const TOOL_INTERFACE& DestInf)
- {
- //遍历现有工具(逆序),找最近的端口链接
- //遍历的时候跳过了工具自身,所以下面下面的初始值为 2
- for (int j = (int)m_SelTools.size() - 2; j >= 0; j--)
- {
- TOOL toolTemp = m_SelTools[j];
- //目前执行的智能链接策略为,逆序找最近的同属性端口,可能不是客户最终需要的端口,所以需要优化
- for (unsigned int k = 0; k < toolTemp.Interfaces.size(); k++)
- {
- const TOOL_INTERFACE& SourceInf = toolTemp.Interfaces[k];
- if ((SourceInf.InfType == INF_VALUE_1 || SourceInf.InfType == INF_VALUE_2 || SourceInf.InfType == INF_VALUE_3 || SourceInf.InfType == INF_VALUE_4)
- && (SourceInf.InfDirection == INF_OUT))
- {
- if (DestInf.VarType == SourceInf.VarType)
- {
- if (DestInf.bSmartLink && SourceInf.bSmartLink)
- {
- AddLink(SourceInf, DestInf);
- return;
- }
- }
- }
- }
- }
- }
- //
- ///////////////////////////////////////////////////////////////
- //// 判断一个节点是否是输入节点
- //BOOL CTaskWindow::IsInputNode(const HTREEITEM& handle)
- //{
- // TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle);
- // if (pInf == NULL)
- // {
- // return FALSE;
- // }
- // ASSERT(pInf != NULL);
- //
- // if (pInf->bWay == INF_IN)
- // {
- // return TRUE;
- // }
- // else
- // {
- // return FALSE;
- // }
- //}
- //
- ///////////////////////////////////////////////////////////////
- //// 判断一个节点是否是输出节点
- //BOOL CTaskWindow::IsOutputNode(const HTREEITEM& handle)
- //{
- // TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle);
- // if (pInf == NULL)
- // {
- // return FALSE;
- // }
- // ASSERT(pInf != NULL);
- //
- // if (pInf->bWay == INF_OUT)
- // {
- // return TRUE;
- // }
- // else
- // {
- // return FALSE;
- // }
- //}
- //////////////////////////////////////////////////////////////////
- // 计算连线的绘制坐标
- LINK_POINTS CTaskWindow::CalcLinkPoints(const LINK& lnk)
- {
- LINK_POINTS lp;
- TOOL_INTERFACE toolStart = lnk.source;
- TOOL_INTERFACE toolEnd = lnk.dest;
- // 根据对应的矩形区域进行绘制
- CRect rcStart, rcEnd;
- TOOL_INTERFACE* pInfStart = GetInterfaceByHandle(toolStart.hHandle);
- TOOL_INTERFACE* pInfEnd = GetInterfaceByHandle(toolEnd.hHandle);
- if (pInfStart && pInfEnd)
- {
- rcStart = pInfStart->rect;
- rcEnd = pInfEnd->rect;
- }
- // TRACE(_T("Start: %d %d %d %d - rcEnd: %d %d %d %d\n"),
- // /*m_wndTree.GetItemText(toolStart.hHandle), m_wndTree.GetItemText(toolEnd.hHandle),*/
- // rcStart.left, rcStart.top, rcStart.right, rcStart.bottom,
- // rcEnd.left, rcEnd.top, rcEnd.right, rcEnd.bottom);
- lp.ptStart.x = rcStart.right;
- lp.ptStart.y = rcStart.top + rcStart.Height() / 2;
- lp.ptEnd.x = rcEnd.right;
- lp.ptEnd.y = rcEnd.top + rcEnd.Height() / 2;
- lp.ptEnd.x = lp.ptEnd.x - PORT_WIDTH;
- if ((lp.ptStart.x < lp.ptEnd.x) && (lp.ptStart.y == lp.ptEnd.y))//1
- lp.nMode = 1;
- else if ((lp.ptStart.x >= lp.ptEnd.x) && (lp.ptStart.y == lp.ptEnd.y))//2
- lp.nMode = 2;
- else if ((lp.ptStart.x <= lp.ptEnd.x) && (lp.ptStart.y >= lp.ptEnd.y))//3
- lp.nMode = 3;
- else if ((lp.ptStart.x < lp.ptEnd.x) && (lp.ptStart.y < lp.ptEnd.y))//4
- lp.nMode = 4;
- else if ((lp.ptStart.x >= lp.ptEnd.x) && (lp.ptStart.y <= lp.ptEnd.y))//5
- lp.nMode = 5;
- else if ((lp.ptStart.y > lp.ptEnd.y) && (lp.ptStart.x > lp.ptEnd.x))//6
- lp.nMode = 6;
- switch (lp.nMode)
- {
- case 1:
- {
- lp.ptCorner1 = lp.ptStart;
- lp.ptCorner2 = lp.ptStart;
- lp.ptCorner3 = lp.ptEnd;
- lp.ptCorner4 = lp.ptEnd;
- }
- break;
- case 2:
- {
- lp.ptCorner1.x = lp.ptStart.x + 10;
- lp.ptCorner1.y = lp.ptStart.y;
- lp.ptCorner4.x = lp.ptEnd.x - 10;
- lp.ptCorner4.y = lp.ptEnd.y;
- lp.ptCorner2.x = lp.ptCorner1.x;
- lp.ptCorner2.y = lp.ptCorner1.y + 10;
- lp.ptCorner3.x = lp.ptCorner4.x;
- lp.ptCorner3.y = lp.ptCorner2.y;
- }
- break;
- case 3:
- case 4:
- {
- lp.ptCorner1.x = (long)((lp.ptEnd.x - lp.ptStart.x) * 0.1) + lp.ptStart.x;
- lp.ptCorner1.y = (long)lp.ptStart.y;
- lp.ptCorner2.x = (long)lp.ptCorner1.x;
- lp.ptCorner2.y = lp.ptEnd.y;
- lp.ptCorner3 = lp.ptCorner2;
- lp.ptCorner4 = lp.ptCorner2;
- }
- break;
- case 5:
- {
- lp.ptCorner1.x = lp.ptStart.x + 10;
- lp.ptCorner1.y = lp.ptStart.y;
- lp.ptCorner4.x = lp.ptEnd.x - 10;
- lp.ptCorner4.y = lp.ptEnd.y;
- lp.ptCorner2.x = lp.ptCorner1.x;
- lp.ptCorner2.y = (long)((lp.ptCorner4.y - lp.ptCorner1.y) * 0.1) + lp.ptCorner1.y;
- lp.ptCorner3.x = lp.ptCorner4.x;
- lp.ptCorner3.y = lp.ptCorner2.y;
- }
- break;
- case 6:
- {
- lp.ptCorner1.x = lp.ptStart.x + 10;
- lp.ptCorner1.y = lp.ptStart.y;
- lp.ptCorner4.x = lp.ptEnd.x - 10;
- lp.ptCorner4.y = lp.ptEnd.y;
- lp.ptCorner2.x = lp.ptCorner1.x;
- lp.ptCorner2.y = (long)((lp.ptCorner1.y - lp.ptCorner4.y) * 0.1) + lp.ptCorner4.y;
- lp.ptCorner3.x = lp.ptCorner4.x;
- lp.ptCorner3.y = lp.ptCorner2.y;
- }
- break;
- default:
- break;
- }
- return lp;
- }
- ////////////////////////////////////////////////////////////
- // 绘制链接
- void CTaskWindow::DrawLink(CDC* pDC)
- {
- if (m_Links.size() <= 0)
- {
- return;
- }
- LINK_MAP::iterator iter;
- for (iter = m_Links.begin(); iter != m_Links.end(); iter++)
- {
- // 计算需要绘制link的联线坐标位置
- LINK_POINTS lps = CalcLinkPoints(*iter);
- // 选择画笔
- CPen *pOldPen = NULL;
- // 根据线条的命中与否选择不同的画笔
- if (iter->bShow)
- {
- if (iter->bActive)
- {
- pOldPen = pDC->SelectObject(&m_penLinkBold);
- }
- else
- {
- pOldPen = pDC->SelectObject(&m_penLink);
- }
- pDC->MoveTo(lps.ptStart);
- pDC->LineTo(lps.ptCorner1);
- pDC->LineTo(lps.ptCorner2);
- pDC->LineTo(lps.ptCorner3);
- pDC->LineTo(lps.ptCorner4);
- pDC->LineTo(lps.ptEnd);
- // 绘制箭头
- CPoint ptArrowTop, ptArrowBottom;
- ptArrowTop.x = lps.ptEnd.x - ARROW_LENGTH;
- ptArrowTop.y = lps.ptEnd.y + ARROW_LENGTH;
- ptArrowBottom.x = ptArrowTop.x;
- ptArrowBottom.y = lps.ptEnd.y - ARROW_LENGTH;
- pDC->LineTo(ptArrowTop);
- pDC->MoveTo(lps.ptEnd);
- pDC->LineTo(ptArrowBottom);
- pDC->SelectObject(pOldPen);
- }
- }
- }
- ////////////////////////////////////////////////////////////
- // 绘制预览链接
- void CTaskWindow::DrawPreviewLink(CDC* pDC)
- {
- if (m_TsetLinks.size() <= 0)
- {
- return;
- }
- LINK_MAP::iterator iter;
- for (iter = m_TsetLinks.begin(); iter != m_TsetLinks.end(); iter++)
- {
- LINK_POINTS lps = CalcLinkPoints(*iter);
- // 选择画笔
- CPen *pOldPen = NULL;
- pOldPen = pDC->SelectObject(&m_penLinkTest);
- pDC->MoveTo(lps.ptStart);
- pDC->LineTo(lps.ptCorner1);
- pDC->LineTo(lps.ptCorner2);
- pDC->LineTo(lps.ptCorner3);
- pDC->LineTo(lps.ptCorner4);
- pDC->LineTo(lps.ptEnd);
- // 绘制箭头
- CPoint ptArrowTop, ptArrowBottom;
- ptArrowTop.x = lps.ptEnd.x - ARROW_LENGTH;
- ptArrowTop.y = lps.ptEnd.y + ARROW_LENGTH;
- ptArrowBottom.x = ptArrowTop.x;
- ptArrowBottom.y = lps.ptEnd.y - ARROW_LENGTH;
- pDC->LineTo(ptArrowTop);
- pDC->MoveTo(lps.ptEnd);
- pDC->LineTo(ptArrowBottom);
- pDC->SelectObject(pOldPen);
- }
- }
- /////////////////////////////////////////////////////////////////////
- // 更新节点数据结构
- void CTaskWindow::UpdateTools(bool bIsLoad )
- {
- CDiagramEntityContainer* objs = static_cast<CDiagramEntityContainer*> (m_editor.GetDiagramEntityContainer());
- if (objs)
- {
- UINT nIndex = 0;
- for (UINT u = 0; u < objs->GetSize(); u++)
- {
- // if (objs->GetAt(u)->GetType() != _T("Tool"))
- // {
- // continue;
- // }
- CFunctionBlock* obj = (CFunctionBlock*)objs->GetAt(u);
- CString strTitle;
- strTitle.Format(_T("%d"), nIndex);
- obj->Tools.nToolID = nIndex;
- obj->SetTitle(strTitle);
- CString strToolShowName = obj->Tools.strShowName;
- BOOL bFind = FALSE;
- UINT i = 0;
- HTREEITEM hParent = obj->Tools.hHandle;
- // 查找当前选中的工具集合中是否有当前的工具
- for (; i < m_SelTools.size(); i++)
- {
- if (m_SelTools[i].strShowName.Compare(strToolShowName) == 0)
- {
- bFind = TRUE;
- break;
- }
- }
- // 如果找到了这个工具,只需要调整一下顺序,然后更新句柄
- if (bFind)
- {
- if (i > nIndex)
- {
- TOOL toolTemp = m_SelTools[i];
- m_SelTools[i] = m_SelTools[nIndex];
- m_SelTools[nIndex] = toolTemp;
- }
- else if (i < nIndex)
- {
- hParent = obj->Tools.hHandle;
- continue;
- }
- UpdateExistTool(m_SelTools[nIndex], obj->Tools);
- //用来在页面上显示工具是否需要触发
- TOOL tool = m_SelTools[nIndex];
- EVEN m_hEven = tool.pDllPtr->m_Even;
- obj->SetToolMode(m_hEven.hEvenHandle);
- nIndex++;
- }
- // 否则是一个新的工具
- else
- {
- UpdateNewTool(strToolShowName, obj->Tools, bIsLoad);
- }
- }
- this->UpdateLink();
- }
- }
- //////////////////////////////////////////////////////////////////
- // 更新现有工具
- void CTaskWindow::UpdateExistTool(TOOL& tool, TOOL& tool_Info)
- {
- // 获取句柄
- tool.hHandle = tool_Info.hHandle;
- tool.rect = tool_Info.rect;
- tool.nToolID = tool_Info.nToolID;
- tool_Info.nInSleep = tool.nInSleep;
- tool_Info.nOutSleep = tool.nOutSleep;
- tool_Info.strLinkName = tool.strLinkName;
- for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
- {
- TOOL_INTERFACE& inf = tool.Interfaces[j];
- {
- inf.hHandle = tool_Info.Interfaces[j].hHandle;
- CRect rect = tool_Info.Interfaces[j].rect;
- if (!rect.IsRectEmpty())
- {
- inf.rect = tool_Info.Interfaces[j].rect;
- }
- if (tool.Type == TOOL_TYPE::TOOL_BY_PROT)
- {
- tool_Info.Interfaces[j].bShow = inf.bShow;
- }
- else
- {
- inf.bShow = tool_Info.Interfaces[j].bShow;
- }
- tool_Info.Interfaces[j].strName = inf.strName;
- tool_Info.Interfaces[j].nUseCount = inf.nUseCount;
- tool_Info.Interfaces[j].strParentName = inf.strParentName;
- }
- }
- }
- /////////////////////////////////////////////////////////////////
- // 更新新工具
- void CTaskWindow::UpdateNewTool(const CString& strToolShowName, TOOL tool_Info, bool bIsLoad )
- {
- CString strToolRealName = GetToolRealname(strToolShowName);
- // 查询对应的工具
- TOOL newTool = g_pTaskView->m_wndTool.GetToolByName(strToolRealName);
- newTool.strShowName = strToolShowName;
- // 获取句柄
- newTool.hHandle = tool_Info.hHandle;
- newTool.rect = tool_Info.rect;
- newTool.strInfo = tool_Info.strInfo;
- newTool.strLinkName = tool_Info.strLinkName;
- newTool.nUseCount = tool_Info.nUseCount;
- for (unsigned int j = 0; j < newTool.Interfaces.size(); j++)
- {
- TOOL_INTERFACE& inf = newTool.Interfaces[j];
- inf.strParentName = strToolShowName;
- inf.hHandle = tool_Info.Interfaces[j].hHandle;
- inf.rect = tool_Info.Interfaces[j].rect;
- inf.nUseCount = tool_Info.Interfaces[j].nUseCount;
- }
- USES_CONVERSION;
- char * s_str = T2A(strToolShowName);
- g_Logger.Info(0, __FILE__, __LINE__, "Task[%d] Add Tool: %s ",m_nIndex, s_str);
- // 从dll获取工具指针
- if (!GetToolPtrByDll(newTool))
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] %s 工具加载dll工具失败!"),m_nIndex, newTool.strShowName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return;
- }
- if (newTool.pDllPtr != NULL)
- {
- //首先注册日志回调,以便在主框架中显示所有的工具日志
- newTool.pDllPtr->setReceLogCallBack(ToolLogCallback, (long long)g_pMainFrame);
- //注册工具状态回调,以便在主框架中显示工具状态
- newTool.pDllPtr->setReceToolStateCallBack(ToolStateCallback, (long long)this);
- //注册工具中的执行回调,以便在工具中执行当前工具
- newTool.pDllPtr->setOnExecuteCallBack(ToolOnExecuteCallback, (long long)this);
- //注册工具中的执行回调,以便在工具中执行当前工具
- newTool.pDllPtr->setToolBusyCallBack(ToolBusyCallback, (long long)this);
- m_SelTools.push_back(newTool);
- //初始化工具
- newTool.pDllPtr->InitTool(g_pMainFrame->GetActiveView(), m_strTaskName, newTool.strShowName);
- }
- if (! bIsLoad)
- {
- if (BCGPMessageBox(_T("是否执行自动数据链接 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("SmartLink .....")) == IDYES)
- SmartLink();
- }
-
- Invalidate(TRUE);
- }
- /////////////////////////////////////////////////////////////////
- // 更新所有节点的连接信息
- void CTaskWindow::UpdateLink()
- {
- // 遍历所有节点,更新对应的句柄信息
- for (unsigned int i = 0; i < m_Links.size(); i++)
- {
- LINK& lnk = m_Links[i];
- for (unsigned int m = 0; m < m_SelTools.size(); m++)
- {
- TOOL& tool = m_SelTools[m];
- for (unsigned int n = 0; n < tool.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& inf = tool.Interfaces[n];
- if (IsSameInterface(lnk.source, inf))
- {
- lnk.source = inf;
- break;
- }
- else if (IsSameInterface(lnk.dest, inf))
- {
- lnk.dest = inf;
- break;
- }
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////
- // 建立连接
- bool CTaskWindow::MakeLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest, bool bShow)
- {
- // 首先检查一下是否有key相同的接口
- LINK_MAP::iterator iter;
- for (iter = m_Links.begin(); iter != m_Links.end(); iter++)
- {
- if (IsSameInterface(dest, iter->dest))
- {
- // 替换现有link
- iter->source = source;
- CString str;
- str.Format(_T("Task[%d] Update link: %s-%s to %s-%s"),m_nIndex,
- source.strParentName, source.strName,
- dest.strParentName, dest.strName);
- USES_CONVERSION;
- char * s_str = T2A(str);
- g_Logger.Debug(0, __FILE__, __LINE__, s_str);
- return TRUE;
- }
- }
- // 否则添加一个新的link
- LINK newLink;
- newLink.source = source;
- newLink.dest = dest;
- newLink.bShow = bShow;
- m_Links.push_back(newLink);
- CString strMsg;
- strMsg.Format(_T("Task[%d] Make link: %s-%s to %s-%s"),m_nIndex,
- newLink.source.strParentName, newLink.source.strName,
- newLink.dest.strParentName, newLink.dest.strName);
- //TRACE(str);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Info(0, __FILE__, __LINE__, s_str);
- return TRUE;
- }
- // 建立连接
- bool CTaskWindow::MakeTestLink(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest)
- {
- // 首先检查一下是否有key相同的接口
- LINK_MAP::iterator iter;
- for (iter = m_TsetLinks.begin(); iter != m_TsetLinks.end(); iter++)
- {
- if (IsSameInterface(dest, iter->dest))
- {
- // 替换现有link
- iter->source = source;
- TRACE(_T("Update link: %s-%s to %s-%s\n"),
- source.strParentName, source.strName,
- dest.strParentName, dest.strName);
- return TRUE;
- }
- }
- // 否则添加一个新的link
- LINK newLink;
- newLink.source = source;
- newLink.dest = dest;
- m_TsetLinks.clear();
- m_TsetLinks.push_back(newLink);
- TRACE(_T("Make link: %s-%s to %s-%s\n"),
- newLink.source.strParentName, newLink.source.strName,
- newLink.dest.strParentName, newLink.dest.strName);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////
- // 根据句柄转换成对应的TOOL
- TOOL* CTaskWindow::GetToolByHandle(const HTREEITEM& handle)
- {
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- if (tool.hHandle == handle)
- {
- return &m_SelTools[i];
- }
- }
- return NULL;
- }
- //////////////////////////////////////////////////////////////////////////
- // 根据显示的名称转换乘对应的TOOL
- TOOL* CTaskWindow::GetToolByShowName(const CString strName)
- {
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- if (tool.strShowName == strName)
- {
- return &m_SelTools[i];
- }
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////
- // 根据句柄转换成对应的Interface
- TOOL_INTERFACE* CTaskWindow::GetInterfaceByHandle(const HTREEITEM& handle)
- {
- for (unsigned int m = 0; m < m_SelTools.size(); m++)
- {
- TOOL& toolSearch = m_SelTools[m];
- for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
- if (infSearch.hHandle == handle)
- {
- return &m_SelTools[m].Interfaces[n];
- }
- }
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////
- // 根据 名字 转换成对应的Interface
- TOOL_INTERFACE* CTaskWindow::GetInterfaceByName(const CString strParentName, const CString strName)
- {
- for (unsigned int m = 0; m < m_SelTools.size(); m++)
- {
- TOOL& toolSearch = m_SelTools[m];
- if (toolSearch.strShowName.Compare(strParentName) == 0)
- {
- for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
- if (infSearch.strName.Compare(strName) == 0)
- {
- return &m_SelTools[m].Interfaces[n];
- }
- }
- }
- }
- return NULL;
- }
- /////////////////////////////////////////////////////////////////
- // 重置整个TaskWindow的相关数据
- void CTaskWindow::Reset()
- {
- // 清空数据结构
- //m_SelTools.clear();
- m_Links.clear();
- m_RenameList.clear();
- m_TsetLinks.clear();
- // 清空树形控件
- // m_wndTree.Clear();
- // m_wndTree.Invalidate(TRUE);
- m_editor.DeleteAll();
- m_editor.Clear();
- m_editor.Invalidate(TRUE);
- // TODO:清空多线程任务相关的状态
- // 第一个线程不退出,需要优化
- if (m_nIndex != 0)
- {
- // 为了使线程退出
- m_bExitThread = true;
- // 为了可使挂起的现场继续执行下去
- SetEvent(m_hExecuteEven);
- SetEvent(m_hDoneEven);
- //释放线程相关的句柄
- RELEASE_HANDLE(m_hDoneEven);
- RELEASE_HANDLE(m_hExecuteEven);
- }
- // 一定要记得清理 dll 指针,否则持续退出会崩溃在系统dll里
- for (size_t i = 0; i < m_SelTools.size(); i++)
- {
- RELEASE_BUFFER(m_SelTools.at(i).pDllPtr);
- FreeLibrary(m_SelTools[i].hDllTool);
- }
- //// 2019-3-23 释放选择的工具
- //for (unsigned int i = 0; i < m_SelTools.size(); i++)
- //{
- // // 调用Release
- // if (m_SelTools[i].hDllTool)
- // {
- // // 调用Release接口
- // typedef void(*RELEASE)();
- // RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE);
- // if (Release)
- // {
- // Release();
- // }
- // FreeLibrary(m_SelTools[i].hDllTool);
- // }
- //}
- m_SelTools.clear();
- }
- ////////////////////////////////////////////////////////////////
- // 获取某个Interface相连的接口
- TOOL_INTERFACE* CTaskWindow::GetHigherLinkInterface(const TOOL_INTERFACE& inf)
- {
- // 遍历所有Link
- for (unsigned int j = 0; j < m_Links.size(); j++)
- {
- LINK& lnk = m_Links[j];
- if (IsSameInterface(lnk.dest, inf))
- {
- return &lnk.source;
- }
- }
- return NULL;
- }
- ///////////////////////////////////////////////////////////////
- // 根据Interface获取Tool
- TOOL* CTaskWindow::GetToolByInterface(TOOL_INTERFACE& inf)
- {
- for (unsigned int m = 0; m < m_SelTools.size(); m++)
- {
- TOOL& toolSearch = m_SelTools[m];
- for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
- if (IsSameInterface(inf, infSearch))
- {
- return &toolSearch;
- }
- }
- }
- // 查找全局变量
- TOOL& toolSearch = g_pMainFrame->m_GlobalValueDlg.m_GV_Tools;
- for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
- if (IsSameInterface(inf, infSearch))
- {
- return &toolSearch;
- }
- }
- return NULL;
- }
- ///////////////////////////////////////////////////////////////
- // 根据Interface获取Interface
- TOOL_INTERFACE* CTaskWindow::GetInterfaceByInterface(TOOL_INTERFACE& inf)
- {
- for (unsigned int m = 0; m < m_SelTools.size(); m++)
- {
- TOOL& toolSearch = m_SelTools[m];
- for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
- if (IsSameInterface(inf, infSearch))
- {
- return &infSearch;
- }
- }
- }
- // 查找全局变量
- TOOL& toolSearch = g_pMainFrame->m_GlobalValueDlg.m_GV_Tools;
- for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
- if (IsSameInterface(inf, infSearch))
- {
- return &infSearch;
- }
- }
- return NULL;
- }
- //////////////////////////////////////////////////////////////////////////
- // 根据Tool获取Tool
- TOOL* CTaskWindow::GetToolByTool(TOOL& tool)
- {
- for (unsigned int m = 0; m < m_SelTools.size(); m++)
- {
- TOOL& toolSearch = m_SelTools[m];
- if (tool.strShowName == toolSearch.strShowName
- && tool.strName == toolSearch.strName
- )
- {
- return &toolSearch;
- }
- }
- return NULL;
- }
- ////////////////////////////////////////////////////////////////////
- // 判断是否是同一个接口
- bool CTaskWindow::IsSameInterface(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest)
- {
- return source.strParentName == dest.strParentName
- && source.strName == dest.strName
- && source.InfDirection == dest.InfDirection
- && source.InfWay == dest.InfWay;
- }
- ///////////////////////////////////////////////////////////
- // 计算连接线的长度
- int CTaskWindow::CalcLinkLineLength(const TOOL_INTERFACE& source, const TOOL_INTERFACE& dest)
- {
- int nLength = 0;
- bool bSearch = false;
- /*
- CString strName = m_wndTree.GetItemText(source.hHandle);
- // TRACE(_T("strName: %s\n"), strName);
- for (unsigned int m = 0; m < m_SelTools.size(); m++)
- {
- TOOL& toolSearch = m_SelTools[m];
- for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
- // CString strName1 = m_wndTree.GetItemText(infSearch.hHandle);
- // TRACE(_T("strName1: %s\n"), strName1);
- if (bSearch)
- {
- CRect rc;
- m_wndTree.GetItemRect(infSearch.hHandle, &rc, TRUE);
- if (rc.right > nLength)
- {
- nLength = rc.right;
- }
- if (IsSameInterface(dest, infSearch))
- {
- return nLength;
- }
- }
- else
- {
- if (IsSameInterface(source, infSearch))
- {
- CRect rc;
- m_wndTree.GetItemRect(source.hHandle, &rc, TRUE);
- nLength = rc.right;
- bSearch = true;
- }
- }
- }
- }
- */
- return nLength;
- }
- /////////////////////////////////////////////////////
- // 通过工具显示的名字查询工具真正的名字
- CString CTaskWindow::GetToolRealname(const CString& strShowName)
- {
- CString strRealName;
- map<CString, CString>::iterator iter;
- for (iter = m_RenameList.begin(); iter != m_RenameList.end(); iter++)
- {
- if (strShowName.Compare(iter->first) == 0)
- {
- strRealName = iter->second;
- return strRealName;
- }
- }
- return strShowName;
- }
- /////////////////////////////////////////////////////////////
- // 计算连线的触发区域
- LINK_RECTS CTaskWindow::CalcLinkRects(const LINK_POINTS& lps)
- {
- LINK_RECTS lrs;
- lrs.rcStart.left = lps.ptStart.x - PORT_WIDTH;
- lrs.rcStart.right = lps.ptCorner1.x;
- lrs.rcStart.top = lps.ptStart.y - HOT_REGION;
- lrs.rcStart.bottom = lps.ptStart.y + HOT_REGION;
- lrs.rcEnd.left = lps.ptCorner4.x;
- lrs.rcEnd.right = lps.ptEnd.x + PORT_WIDTH;
- lrs.rcEnd.top = lps.ptEnd.y - HOT_REGION;
- lrs.rcEnd.bottom = lps.ptEnd.y + HOT_REGION;
- lrs.rcCorner1.left = lps.ptCorner1.x - HOT_REGION;
- lrs.rcCorner1.right = lps.ptCorner1.x + HOT_REGION;
- switch (lps.nMode)
- {
- case 1:
- case 2:
- case 3:
- case 4:
- lrs.rcCorner1.top = lrs.rcStart.top < lrs.rcEnd.top ? lrs.rcStart.top : lrs.rcEnd.top;
- lrs.rcCorner1.bottom = lrs.rcStart.bottom > lrs.rcEnd.bottom ? lrs.rcStart.bottom : lrs.rcEnd.bottom;
- break;
- case 5:
- lrs.rcCorner1.top = lrs.rcStart.top < lrs.rcEnd.top ? lrs.rcStart.top : lrs.rcEnd.top;
- lrs.rcCorner1.bottom = lps.ptCorner2.y;
- break;
- case 6:
- lrs.rcCorner1.top = lps.ptCorner2.y;
- lrs.rcCorner1.bottom = lps.ptStart.y;
- break;
- default:
- break;
- }
- lrs.rcCorner3.left = lps.ptCorner3.x - HOT_REGION;
- lrs.rcCorner3.right = lps.ptCorner3.x + HOT_REGION;
- if (lps.nMode == 5)
- {
- lrs.rcCorner3.top = lps.ptCorner3.y;
- lrs.rcCorner3.bottom = lps.ptEnd.y;
- }if (lps.nMode == 6)
- {
- lrs.rcCorner3.top = lps.ptEnd.y;
- lrs.rcCorner3.bottom = lps.ptCorner3.y;
- }
- lrs.rcCorner2.left = lps.ptCorner3.x;
- lrs.rcCorner2.right = lps.ptCorner1.x;
- lrs.rcCorner2.top = lps.ptCorner3.y - HOT_REGION;
- lrs.rcCorner2.bottom = lps.ptCorner3.y + HOT_REGION;
- return lrs;
- }
- ///////////////////////////////////////////////////////
- // 鼠标左键按下时,激活连线
- void CTaskWindow::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // 循环遍历所有连线区域,查找是否有命中的
- CPoint pt = point;
- m_editor.ScreenToVirtual(pt);
- LINK_MAP::iterator iter;
- // 然后查找命中
- for (iter = m_Links.begin(); iter != m_Links.end(); iter++)
- {
- // 计算这个连线的矩形区域
- LINK_POINTS lps = CalcLinkPoints(*iter);
- LINK_RECTS lrs = CalcLinkRects(lps);
- // 判断鼠标是否命中
- if (PtInRect(&lrs.rcStart, pt) || PtInRect(&lrs.rcEnd, pt) ||
- PtInRect(&lrs.rcCorner1, pt) || PtInRect(&lrs.rcCorner2, pt) ||
- PtInRect(&lrs.rcCorner3, pt)
- )
- {
- // 如果命中,则把这条线设置为命中状态
- iter->bActive = TRUE;
- // 然后把其他连接设置为未命中状态
- for (unsigned int i = 0; i < m_Links.size(); i++)
- {
- if (*iter != m_Links[i])
- {
- m_Links[i].bActive = FALSE;
- }
- }
- // Invalidate(TRUE);
- break;
- }
- else
- {
- //点击空白处,将所有连线设置为未选中状态
- for (unsigned int i = 0; i < m_Links.size(); i++)
- {
- m_Links[i].bActive = FALSE;
- }
- }
- }
- CBCGPStatic::OnLButtonDown(nFlags, point);
- }
- //////////////////////////////////////////////////////////////////////////
- // 当 Item单击时候
- void CTaskWindow::OnItemLButtonDown(const HTREEITEM& handle)
- {
- TOOL* pActiveTool = GetToolByHandle(handle);
- if (pActiveTool == NULL)
- {
- return;
- }
- // 根据Tool的指针调用函数
- if (pActiveTool != NULL)
- {
- DEUBGOBJ obj = pActiveTool->pDllPtr->GetDeubgDispObj();
- g_pTaskView->m_wndDisp.AddImage(obj.mImage);
- g_pTaskView->m_wndDisp.AddOjb(obj.mObj);
- g_pTaskView->m_wndDisp.Refresh();
- }
- }
- ////////////////////////////////////////////////////////
- // 当Item双击时
- void CTaskWindow::OnItemDblclk(const HTREEITEM& handle)
- {
- // 根据句柄查询到工具
- TOOL* pActiveTool = GetToolByHandle(handle);
- if (pActiveTool == NULL)
- {
- return;
- }
- if (pActiveTool->Type == TOOL_TYPE::TOOL_BY_PROT && pActiveTool->strLinkName.IsEmpty() )
- {
- CDialogLink dlgLink;
- dlgLink.m_InfType = INF_TYPE::INF_VALUE_1;
- dlgLink.m_LinkVarType = VAR_TYPE::ALL_Var;
- dlgLink.m_Direction = INF_DIRECTION::INF_OUT;
- for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++)
- {
- TOOL_INTERFACE inf = pActiveTool->Interfaces[i];
- if (inf.InfDirection == INF_DIRECTION::INF_OUT && inf.bShow == true)
- {
- dlgLink.m_LinkVarType = inf.VarType;
- }
- }
- if (dlgLink.DoModal() == IDOK)
- {
- for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++)
- {
- TOOL_INTERFACE inf = pActiveTool->Interfaces[i];
- if (inf.InfDirection == INF_DIRECTION::INF_IN && inf.VarType == dlgLink.m_SelInterface.VarType)
- {
- TOOL_INTERFACE* pInfSource = GetInterfaceByInterface(dlgLink.m_SelInterface);
- TOOL_INTERFACE* pInfDest = GetInterfaceByInterface(inf);
- ASSERT(pInfDest != NULL);
- if (pInfDest != NULL && pInfSource != NULL /*&& dlgLink.m_nTaskIndex != TASK_SYSTEM_GV*/)
- {
-
- if (dlgLink.m_nTaskIndex == TASK_SYSTEM_GV)
- {
- pInfSource = g_pMainFrame->m_GlobalValueDlg.GetInterfaceByInterface(dlgLink.m_SelInterface);
- for (UINT i = 0; i < pActiveTool->Interfaces.size(); i++)
- {
- TOOL_INTERFACE& inf = pActiveTool->Interfaces[i];
-
- if (inf.InfDirection == INF_DIRECTION::INF_OUT && inf.VarType == dlgLink.m_SelInterface.VarType)
- {
- inf.bShow = true;
- }
- }
- }
- // 内部引用计数加一
- pInfSource->nUseCount ++;
- pInfDest->nUseCount++;
- const TOOL_INTERFACE source = *pInfSource;
- const TOOL_INTERFACE dest = *pInfDest;
- MakeLink(source, dest, false);
- pInfDest->bShow = true;
- CString strLink;
- strLink.Format(_T("%s.%s.Q"),
- dlgLink.m_SelInterface.strParentName,
- dlgLink.m_SelInterface.strName);
- pActiveTool->strLinkName = strLink;
- UpdateTools();
- }
- else
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] Link Error %s.%s --> %s.%s "), m_nIndex,
- dlgLink.m_SelInterface.strParentName, dlgLink.m_SelInterface.strName, inf.strParentName, inf.strName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- }
- }
- }
- }
- }
- // 根据Tool的指针调用函数
- if (pActiveTool != NULL)
- {
- if (pActiveTool->bEnable == false)
- {
- g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作....."));
- return;
- }
- pActiveTool->pDllPtr->ShowDialog(m_strTaskName, pActiveTool->strShowName);
- }
- }
- ////////////////////////////////////////////////////////
- // 当Item双击时 子节点
- void CTaskWindow::OnItemNodeDblclk(const HTREEITEM& handle)
- {
- TOOL_INTERFACE* pInf = GetInterfaceByHandle(handle);
- if (pInf != NULL)
- {
- if (pInf->InfDirection == INF_DIRECTION::INF_IN && pInf->nUseCount == 0)
- {
- if (BCGPMessageBox(_T("是否添加 Prot 端口"), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Add Prot .....")) == IDYES)
- {
- TOOL* pDestTool = GetToolByShowName(pInf->strParentName);// 点击的模块(工具实体模块)
- pInf->rect.TopLeft().x -= 150;
- pInf->rect.TopLeft().y -= 5;
- TOOL newTool;
- newTool.strName = _T("InPutProt");
- newTool.strShowName = _T("InPutProt");
- newTool.rect = pInf->rect;
- CString strShowName;
- AddNewTools2(newTool, &strShowName);
- UpdateTools();
- TOOL* pSourceTool = GetToolByShowName(strShowName);
- if (pSourceTool != NULL)
- {
- bool bFindStatus = false;
- //////////////////////////////////////////////////////////////////////////
- // 此处搜索的是Prot模块
- for (UINT i = 0; i < pSourceTool->Interfaces.size(); i++)
- {
- TOOL_INTERFACE& inf = pSourceTool->Interfaces[i];
- if (inf.InfDirection == INF_DIRECTION::INF_OUT)
- {
- TOOL_INTERFACE* pDestInf = GetInterfaceByHandle(handle);
- if (inf.VarType == pDestInf->VarType && inf.strParentName != pDestInf->strParentName)
- {
- // 如果再prot模块里能找到对应的数据类型,就可以创建数据链接(源数据)
- bFindStatus = true;
- inf.bShow = true;
- BOOL status = AddLink(inf, *pDestInf);
- if (!status)
- {
- g_Logger.Error(0, NULL, NULL, "Task[%d] Link Error %s.%s --> %s.%s ",m_nIndex, inf.strParentName, inf.strName, pDestInf->strParentName, pDestInf->strName);
- }
- CString strMsg;
- strMsg.Format(_T("Task[%d] Link OK %s.%s --> %s.%s "),m_nIndex, inf.strParentName, inf.strName, pDestInf->strParentName, pDestInf->strName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Debug(0, __FILE__, __LINE__, s_str);
- }
- }
- }
- if (!bFindStatus)
- {
- TOOL_INTERFACE* pDestInf = GetInterfaceByHandle(handle);
- if (pDestInf)
- {
- g_Logger.Error(0, NULL, NULL, "Task[%d] Find Prot Error %s.%s --> %s.%s [%d]",m_nIndex, pDestInf->strParentName, pDestInf->strName, pDestInf->VarType);
- }
- else
- {
- g_Logger.Error(0, NULL, NULL, "Task[%d] Find Prot Error",m_nIndex);
- }
-
- }
- UpdateTools();
- //重新排序too的序号,使Prot序号 小于当前工具的序号
- SortProtToolID (pSourceTool,pDestTool);
- }
- }
- }
- if (pInf->InfDirection == INF_DIRECTION::INF_OUT)
- {
- ShowNodeWatch(pInf);
- }
- }
- }
- ////////////////////////////////////////////////////////////
- // 鼠标右键删除的时候
- bool CTaskWindow::OnItemEnable(const HTREEITEM& handle)
- {
- // 根据句柄查询到工具
- TOOL* pActiveTool = GetToolByHandle(handle);
- ASSERT(pActiveTool != NULL);
- if (pActiveTool == NULL)
- {
- return false;
- }
- CString strToolName = pActiveTool->strShowName;
- // BCGPMessageBox(strToolName);
- pActiveTool->bEnable = !pActiveTool->bEnable;
- return pActiveTool->bEnable;
- }
- ////////////////////////////////////////////////////////////
- // 鼠标右键删除的时候
- void CTaskWindow::OnItemDelete(const HTREEITEM& handle)
- {
- // 根据句柄查询到工具
- TOOL* pActiveTool = GetToolByHandle(handle);
- ASSERT(pActiveTool != NULL);
- if (pActiveTool == NULL)
- {
- return;
- }
- CString strToolName = pActiveTool->strShowName;
- // 删除选择工具集中的信息
- vector<TOOL>::iterator itTool;
- for (itTool = m_SelTools.begin(); itTool != m_SelTools.end(); )
- {
- if (itTool->strShowName.Compare(strToolName) == 0)
- {
- RELEASE_BUFFER(itTool->pDllPtr);
- FreeLibrary(itTool->hDllTool);
- itTool = m_SelTools.erase(itTool);
- break;
- }
- else
- {
- ++itTool;
- }
- }
- // 删除重命名列表中的信息
- m_RenameList.erase(strToolName);
- m_editor.RedrawWindow();
- Invalidate(TRUE);
- CString strMsg;
- strMsg.Format(_T("Task[%d] Delete Tools:%s ") ,m_nIndex, strToolName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Warn(0, __FILE__, __LINE__, s_str);
- }
- bool CTaskWindow::IsLink(const HTREEITEM& handle)
- {
- // 根据句柄查询到工具
- TOOL* pActiveTool = GetToolByHandle(handle);
- //ASSERT(pActiveTool != NULL);
- if (pActiveTool == NULL)
- {
- return false;
- }
- CString strToolName = pActiveTool->strShowName;
- bool bIsLink = false;
- vector<LINK>::iterator itLink;
- for (itLink = m_Links.begin(); itLink != m_Links.end(); )
- {
- if ((itLink->source.strParentName.Compare(strToolName) == 0)
- || (itLink->dest.strParentName.Compare(strToolName) == 0))
- {
- //itLink = m_Links.erase(itLink);
- CString strMsg;
- 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);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Debug(0, __FILE__, __LINE__, s_str);
- bIsLink = true;
- break;
- }
- else
- {
- ++itLink;
- }
- }
- return bIsLink;
- }
- // 判断是否受保护
- bool CTaskWindow::IsProtected(const HTREEITEM& handle)
- {
- // 根据句柄查询到工具
- TOOL* pTool = GetToolByHandle(handle);
- ASSERT(pTool != NULL);
- if (pTool == NULL)
- {
- return true;
- }
- if (pTool->nUseCount)
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] Tool Protected %s UseCount[ %d ]"),m_nIndex, pTool->strShowName, pTool->nUseCount);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Debug(0, __FILE__, __LINE__, s_str);
- return true;
- }
- // 遍历本工具下的所有接口
- bool bIsProtected = false;
- for (unsigned int k = 0; k < pTool->Interfaces.size(); k++)
- {
- const TOOL_INTERFACE& inf = pTool->Interfaces[k];
- if (inf.nUseCount)
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] Prot Protected %s.%s UseCount[ %d ]"),m_nIndex, inf.strParentName, inf.strName, inf.nUseCount);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Debug(0, __FILE__, __LINE__, s_str);
- bIsProtected = true;
- }
- }
- return bIsProtected;
- }
- ////////////////////////////////////////////////////////////////
- // 用户右键菜单选择了工具重命名
- void CTaskWindow::OnItemToolRename(const HTREEITEM& handle)
- {
- // 根据句柄查询到工具
- TOOL* pActiveTool = GetToolByHandle(handle);
- CString strOldName = pActiveTool->strShowName;
- if (pActiveTool->bEnable == false)
- {
- g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作....."));
- return;
- }
- //修改处理模块名称
- CToolRenameDlg ToolRename;
- ToolRename.SetToolName(strOldName);
- if (ToolRename.DoModal() == IDOK)
- {
- CString strNewName = ToolRename.GetToolName();
- CString strInfo;
- strInfo.Format(_T("Task[%d] 修改工具名称( %s )为( %s)"),m_nIndex, strOldName, strNewName);
- // 修改界面显示的名字
- pActiveTool->strShowName = strNewName;
- CDiagramEntityContainer* objs = static_cast<CDiagramEntityContainer*> (m_editor.GetDiagramEntityContainer());
- if (objs)
- {
- for (UINT nIndex = 0; nIndex < objs->GetSize(); nIndex++)
- {
- CFunctionBlock& obj = *(CFunctionBlock*)objs->GetAt(nIndex);
- if (obj.Tools.strShowName.Compare(strOldName) == 0)
- {
- obj.Tools.strShowName = strNewName;
- break;
- }
- }
- }
- // 界面重绘
- Invalidate(TRUE);
- OUTPUT_MSG msg;
- msg.strMsg = strInfo;
- USES_CONVERSION;
- char * s_str = T2A(msg.strMsg);
- g_Logger.Debug(0, __FILE__, __LINE__, s_str);
- //g_pMainFrame->SendMessage(DOC_CHANGE);
- // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步)
- for (UINT i = 0; i < m_SelTools.size(); i++)
- {
- for (UINT j = 0; j < m_SelTools[i].Interfaces.size(); j++)
- {
- TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j];
- if (inf.strParentName.Compare(strOldName) == 0)
- {
- inf.strParentName = strNewName;
- }
- }
- }
- // 修改重命名链表
- m_RenameList.erase(strOldName);
- m_RenameList.insert(pair<CString, CString>(strNewName, pActiveTool->strName));
- // 修改Link信息
- for (UINT i = 0; i < m_Links.size(); i++)
- {
- LINK& link = m_Links[i];
- if (link.source.strParentName.Compare(strOldName) == 0)
- {
- link.source.strParentName = strNewName;
- }
- else if (link.dest.strParentName.Compare(strOldName) == 0)
- {
- link.dest.strParentName = strNewName;
- }
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////
- // 编辑工具名称
- void CTaskWindow::ToolRename(TOOL* pTool, const CString strNewName)
- {
- CString strOldName = pTool->strShowName;
- if (pTool->bEnable == false)
- {
- g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("被禁用的工具,禁止该操作....."));
- return;
- }
- // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步)
- for (UINT i = 0; i < m_SelTools.size(); i++)
- {
- TOOL & tool = m_SelTools[i];
- if (tool.strShowName == strNewName)
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] 修改工具名称( %s )为( %s) 失败"),m_nIndex, strOldName, strNewName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return;
- }
- }
- //修改处理模块名称
- {
- CString strInfo;
- strInfo.Format(_T("Task[%d] 修改工具名称( %s )为( %s)"),m_nIndex, strOldName, strNewName);
- // 修改界面显示的名字
- pTool->strShowName = strNewName;
- CDiagramEntityContainer* objs = static_cast<CDiagramEntityContainer*> (m_editor.GetDiagramEntityContainer());
- if (objs)
- {
- for (UINT nIndex = 0; nIndex < objs->GetSize(); nIndex++)
- {
- CFunctionBlock& obj = *(CFunctionBlock*)objs->GetAt(nIndex);
- if (obj.Tools.strShowName.Compare(strOldName) == 0)
- {
- obj.Tools.strShowName = strNewName;
- break;
- }
- }
- }
- // 界面重绘
- Invalidate(TRUE);
- USES_CONVERSION;
- char * s_str = T2A(strInfo);
- g_Logger.Debug(0, __FILE__, __LINE__, s_str);
- //g_pMainFrame->SendMessage(DOC_CHANGE);
- // 修改所有的Tool里的Parent信息(TODO:可能不需要这一步)
- for (UINT i = 0; i < m_SelTools.size(); i++)
- {
- for (UINT j = 0; j < m_SelTools[i].Interfaces.size(); j++)
- {
- TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j];
- if (inf.strParentName.Compare(strOldName) == 0)
- {
- inf.strParentName = strNewName;
- }
- }
- }
- // 修改重命名链表
- m_RenameList.erase(strOldName);
- m_RenameList.insert(pair<CString, CString>(strNewName, pTool->strName));
- // 修改Link信息
- for (UINT i = 0; i < m_Links.size(); i++)
- {
- LINK& link = m_Links[i];
- if (link.source.strParentName.Compare(strOldName) == 0)
- {
- link.source.strParentName = strNewName;
- }
- else if (link.dest.strParentName.Compare(strOldName) == 0)
- {
- link.dest.strParentName = strNewName;
- }
- }
- }
- }
- //////////////////////////////////////////////////////////
- // 右键菜单Link to/from ...
- void CTaskWindow::OnItemLink(const HTREEITEM& source, UINT nLinkDestIndex)
- {
- ASSERT(nLinkDestIndex >= 0);
- TOOL_INTERFACE* pInfSource = GetInterfaceByHandle(source);
- TOOL_INTERFACE* pInfDest = &m_PopLinkNodes.at(nLinkDestIndex);
- // 建立连接
- if (pInfSource->InfDirection == INF_IN)
- {
- AddLink(*pInfDest, *pInfSource);
- }
- else
- {
- AddLink(*pInfSource, *pInfDest);
- }
- // 清空右键link链表
- m_PopLinkNodes.clear();
- }
- /////////////////////////////////////////////////////////
- // 右键菜单UnLink
- void CTaskWindow::OnItemUnLink(HTREEITEM hSelItem)
- {
- // 查找当前的link信息,取消与之相关的连接
- bool bUnLink = false;
- vector<LINK>::iterator it;
- for (it = m_Links.begin(); it != m_Links.end(); )
- {
- LINK& link = *it;
- if (link.source.hHandle == hSelItem
- || link.dest.hHandle == hSelItem)
- {
- TOOL_INTERFACE* pSourceInf = GetInterfaceByInterface(link.source);
- ASSERT(pSourceInf != NULL);
- pSourceInf->nUseCount--;
- TOOL_INTERFACE* pDestInf = GetInterfaceByInterface(link.dest);
- ASSERT(pDestInf != NULL);
- pDestInf->nUseCount--;
- it = m_Links.erase(it);
- bUnLink = true;
- }
- else
- {
- it++;
- }
- }
- if (!bUnLink)
- {
- TOOL_INTERFACE* pInf = GetInterfaceByHandle(hSelItem);
- if (pInf != NULL)
- {
- pInf->nUseCount = 0;
- }
- }
-
- }
- ////////////////////////////////////////////////////////
- // 根据右键菜单获取可以link的接口
- INF_DIRECTION CTaskWindow::GetPopLinkNodes(std::vector<TOOL_INTERFACE>& PopLinkNodes, HTREEITEM hSelItem)
- {
- m_PopLinkNodes.clear();
- INF_DIRECTION dir = INF_NONE;
- // 首先找到用户选中的接口
- TOOL_INTERFACE* pInf = GetInterfaceByHandle(hSelItem);
- if (pInf == NULL)
- {
- return dir;
- }
- dir = pInf->InfDirection;
- // 然后继续寻找所有的本接口可以关联的接口
- for (unsigned int m = 0; m < m_SelTools.size(); m++)
- {
- TOOL& toolSearch = m_SelTools[m];
- for (unsigned int n = 0; n < toolSearch.Interfaces.size(); n++)
- {
- TOOL_INTERFACE& infSearch = toolSearch.Interfaces[n];
- if (IsSameInterface(*pInf, infSearch))
- {
- continue;
- }
- // IN/OUT匹配,并且数据类型一致,并且不从属于同一个Tool
- // 则认为是可以link的接口
- if (pInf->VarType == (infSearch.VarType)
- && pInf->InfDirection != infSearch.InfDirection
- && pInf->strParentName.Compare(infSearch.strParentName) != 0
- )
- {
- m_PopLinkNodes.push_back(infSearch);
- }
- }
- }
- PopLinkNodes = m_PopLinkNodes;
- return dir;
- }
- //////////////////////////////////////////////////
- // 为Tool添加执行结果的图标
- void CTaskWindow::DrawToolColour(NMLVCUSTOMDRAW* pLVCD)
- {
- pLVCD->clrText = globalData.clrBarText; // 这样设置文字颜色
- HTREEITEM hItem = (HTREEITEM)pLVCD->nmcd.dwItemSpec;
- LPTOOL pTool = GetToolByHandle(hItem);
- if ((pTool == NULL) ||
- ((pTool->nExecCode == RT_NONE) && (pTool->nToolState != TOOL_ERROR)))
- {
- return;
- }
- // 用于在当前工具返回错误时候,用不同颜色标记
- if (pTool->nToolState == TOOL_ERROR)
- {
- pLVCD->clrTextBk = RGB(255, 0, 0); // 设置文字背景颜色
- }
- else
- {
- pLVCD->clrTextBk = globalData.clrBarHilite; // 设置文字背景颜色
- pLVCD->clrText = globalData.clrBarText;
- // ::GetSysColor(COLOR_HIGHLIGHT);
- // ::GetSysColorBrush(COLOR_HIGHLIGHT);
- }
- }
- //////////////////////////////////////////////////
- // 为Tool添加执行结果的图标
- void CTaskWindow::DrawToolResult(NMLVCUSTOMDRAW* pLVCD)
- {
- /*
- HTREEITEM hItem = (HTREEITEM)pLVCD->nmcd.dwItemSpec;
- LPTOOL pTool = GetToolByHandle(hItem);
- if ((pTool == NULL) ||
- ((pTool->nExecCode == RT_NONE) && (pTool->nToolState != TOOL_ERROR)))
- {
- return;
- }
- CRect textRect;
- m_wndTree.GetItemRect(hItem, &textRect, TRUE);
- CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
- // 画图采用双缓冲
- CDC memDC;
- memDC.CreateCompatibleDC(pDC);
- // 选择图片对象
- CBitmap *pOldBitmap = NULL;
- // 位图长宽获取
- BITMAP bmInfo;
- if (pTool->nToolState == TOOL_ERROR)
- {
- memDC.SelectObject(&m_Bitmap[0]);
- m_Bitmap[0].GetObject(sizeof(BITMAP), &bmInfo);
- }
- else if (pTool->bEnable == false)//如果工具未启用,图标设置为新的
- {
- memDC.SelectObject(&m_Bitmap[0]);
- m_Bitmap[0].GetObject(sizeof(BITMAP), &bmInfo);
- }
- else if (pTool->nExecCode == RT_SUCCESS)
- {
- memDC.SelectObject(&m_Bitmap[2]);
- m_Bitmap[2].GetObject(sizeof(BITMAP), &bmInfo);
- }
- else
- {
- memDC.SelectObject(&m_Bitmap[1]);
- m_Bitmap[1].GetObject(sizeof(BITMAP), &bmInfo);
- }
- // 输出图片
- pDC->BitBlt(textRect.right, textRect.top, bmInfo.bmWidth, bmInfo.bmHeight, &memDC, 0, 0, SRCCOPY);
- // 删除DC
- memDC.SelectObject(pOldBitmap);
- memDC.DeleteDC();
- */
- }
- //////////////////////////////////////////////////////////
- // 任务窗口序列化
- BOOL CTaskWindow::DoSerialize(CArchive& ar)
- {
- // 保存工具
- if (ar.IsStoring())
- {
- if (!SaveToFile(ar))
- {
- return FALSE;
- }
- }
- // 读取工具信息
- else
- {
- theApp.UpdateSplash(_T("CTaskWindow::DoSerialize()"));
- // 重置链表
- m_RenameList.clear();
- // 2019-3-23 释放选择的工具
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- // 调用Release
- if (m_SelTools[i].hDllTool)
- {
- // 调用Release接口
- typedef void(*RELEASE)();
- RELEASE Release = (RELEASE)GetProcAddress(m_SelTools[i].hDllTool, FUNCTION_RELEASE);
- if (Release)
- {
- Release();
- }
- FreeLibrary(m_SelTools[i].hDllTool);
- }
- }
- m_SelTools.clear();
- if (!LoadFromFile(ar))
- {
- return FALSE;
- }
- }
- // 这段代码之前需要保存流程栏的工具和连线
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- USES_CONVERSION;
- char * s_str = T2A(tool.strShowName);
- try
- {
- theApp.UpdateSplash(tool.strShowName + _T("DoSerialize()"));
- tool.pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion);
- }
- catch (...)
- {
- // CString strMsg;
- // strMsg.Format(_T("%s Tool Serialize Error"), tool.strShowName);
- //
- // OUTPUT_MSG msg;
- // msg.bWay = MSG_WAY::_ERROR;
- // msg.strMsg = strMsg;
- g_Logger.Error(0, __FILE__, __LINE__, ("%s Tool Serialize Error"), s_str);
- }
- }
- m_editor.RedrawWindow();
- return TRUE;
- }
- // 保存工具信息到文件中
- BOOL CTaskWindow::SaveToFile(CArchive& ar)
- {
- int nParanum;//参数数量
- nParanum = 8;//以下参数的数量
- ar << nParanum;
- ar << (int)1 << (int)m_editor.GetVirtualSize().cx;
- ar << (int)2 << (int)m_editor.GetVirtualSize().cy;
- ar << (int)3 << (int)m_editor.GetGridSize().cx;
- ar << (int)4 << (int)m_editor.GetGridSize().cy;
- ar << (int)5 << (int)m_nMarginLeft;
- ar << (int)6 << (int)m_nMarginTop;
- ar << (int)7 << (int)m_nMarginBottom;
- ar << (int)8 << (int)m_nMarginRight;
- nParanum = 16;//以下参数的数量
- ar << nParanum;//先保存参数数量
- ar << (UINT)m_SelTools.size();
- for (UINT i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- // 版本
- ar << (int)1 << tool.strVersion;
- // 名称
- ar << (int)2 << tool.strName;
- // 显示名称
- ar << (int)3 << tool.strShowName;
- // dll路径
- ar << (int)4 << tool.strDll;
- // 是否展开
- ar << (int)5 << tool.bIsExpand;
- // 是否启用
- ar << (int)6 << tool.bEnable;
- //
- ar << (int)7 << (int)tool.Type;
- // 区域
- ar << (int)8 << tool.rect;
- ar << (int)9 << tool.strLinkName;
- ar << (int)10 << tool.nInSleep;
- ar << (int)11 << tool.nOutSleep;
- ar << (int)12 << tool.strInfo;
- ar << (int)13 << tool.hNextTool.nToolID;
- ar << (int)14 << tool.hNextTool.strName;
- ar << (int)15 << tool.hNextTool.strShowName;
- ar << (int)16 << tool.nUseCount;
- //////////////////////////////////////////////////////////////////////////
- int nParanum_Inf = 9;
- ar << nParanum_Inf;//先保存参数数量
- ar << (UINT)tool.Interfaces.size();
- for (UINT i = 0; i < tool.Interfaces.size(); i++)
- {
- TOOL_INTERFACE inf = tool.Interfaces[i];
- ar << (int)1 << inf.strParentName;
- ar << (int)2 << inf.bShow;
- ar << (int)3 << inf.strName;
- ar << (int)4 << (int)inf.VarType;
- ar << (int)5 << (int)inf.InfDirection;
- ar << (int)6 << inf.rect;
- ar << (int)7 << (int)inf.InfType;
- ar << (int)8 << (int)inf.InfWay;
- ar << (int)9 << inf.nUseCount;
- }
- }
- // 保存link
- nParanum = 15;//以下参数的数量
- ar << nParanum;//先保存参数数量
- ar << (UINT)m_Links.size();
- LINK_MAP::iterator iter;
- for (iter = m_Links.begin(); iter != m_Links.end(); iter++)
- {
- ar << (int)1 << iter->source.strParentName;
- ar << (int)2 << iter->source.nIndex;
- ar << (int)3 << iter->dest.strParentName;
- ar << (int)4 << iter->dest.nIndex;
- ar << (int)5 << (int)iter->source.VarType;
- ar << (int)6 << (int)iter->dest.VarType;
- ar << (int)7 << iter->source.InfDirection;
- ar << (int)8 << iter->dest.InfDirection;
- ar << (int)9 << iter->source.strName;
- ar << (int)10 << iter->dest.strName;
- ar << (int)11 << (int)iter->source.InfType;
- ar << (int)12 << (int)iter->dest.InfType;
- ar << (int)13 << (int)iter->source.InfWay;
- ar << (int)14 << (int)iter->dest.InfWay;
- ar << (int)15 << (int)iter->bShow;
- }
- // 保存监控列表
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- nParanum = 2;//以下参数的数量
- ar << nParanum;//先保存参数数量
- ar << (UINT)tool.Interfaces.size();
- for (unsigned int j = 0; j < tool.Interfaces.size(); j++)
- {
- TOOL_INTERFACE& inf = tool.Interfaces[j];
- ar << (int)1 << inf.nIndex;
- ar << (int)2 << inf.bMonitor;
- }
- }
- return TRUE;
- }
- //////////////////////////////////////////////////
- // 从文件中加载工具信息
- BOOL CTaskWindow::LoadFromFile(CArchive& ar)
- {
- UINT nSize = 0;
- vector<TOOL> newTools;
- int nParanum = 0;//参数数量
- int nPpara = 0;
- //初始文件版本号从 101 开始添加,以前文件无版本号
- if (g_nDocVersion > 101)
- {
- int m_nWindowHeight = 0;
- int m_nWindowWidth = 0;
- int m_gridHeight = 0;
- int m_gridWidth = 0;
- int m_marginLeft = 0;
- int m_marginTop = 0;
- int m_marginBottom = 0;
- int m_marginRight = 0;
- ar >> nParanum;
- // 读取窗体信息
- for (int i = 0; i < nParanum; i++)
- {
- ar >> nPpara;
- switch (nPpara)
- {
- case 1: ar >> m_nWindowWidth; break;
- case 2: ar >> m_nWindowHeight; break;
- case 3: ar >> m_gridWidth; break;
- case 4: ar >> m_gridHeight; break;
- case 5: ar >> m_marginLeft; break;
- case 6: ar >> m_marginTop; break;
- case 7: ar >> m_marginBottom; break;
- case 8: ar >> m_marginRight; break;
- default:
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载失败!配置文档错误! "),m_nIndex);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE;
- }
- }
- m_editor.SetVirtualSize(CSize(m_nWindowWidth, m_nWindowHeight));
- m_editor.SetGridSize(CSize(m_gridWidth, m_gridHeight));
- m_editor.SetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom);
- m_editor.RedrawWindow();
- }
- ar >> nParanum;//读取参数数量
- ar >> nSize;
- for (UINT i = 0; i < nSize; i++)
- {
- TOOL newTool;
- for (int j = 0; j < nParanum; j++)
- {
- ar >> nPpara;
- switch (nPpara)
- {
- case 1: ar >> newTool.strVersion; break;// 版本
- case 2: ar >> newTool.strName; break;// 显示名称
- case 3: ar >> newTool.strShowName; break;// 名称
- case 4: ar >> newTool.strDll; break;// dll 路径
- case 5: ar >> newTool.bIsExpand; break;// 是否展开
- case 6: ar >> newTool.bEnable; break;// 是否启用
- case 7: ar >> (int&)newTool.Type; break;// Type
- case 8: ar >> newTool.rect; break;// 区域
- case 9: ar >> newTool.strLinkName; break;//
- case 10: ar >> newTool.nInSleep; break;//
- case 11: ar >> newTool.nOutSleep; break;//
- case 12: ar >> newTool.strInfo; break;//
- case 13: ar >> newTool.hNextTool.nToolID; break;//
- case 14: ar >> newTool.hNextTool.strName; break;//
- case 15: ar >> newTool.hNextTool.strShowName; break;//
- case 16:
- {
- if (g_nDocVersion > 106)
- ar >> newTool.nUseCount;
- else
- ar >> (bool&)newTool.nUseCount;// 106之前,此变量为bool类型
- }break;;//
- default:
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll);
- //CUtility::CriticalBCGPMessageBox(strMsg);
- OUTPUT_MSG msg;
- msg.bWay = MSG_WAY::_ERROR;
- msg.strMsg = strMsg;
- USES_CONVERSION;
- char * s_str = T2A(msg.strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE; break;
- }
- }
- //初始文件版本号从 101 开始添加,以前文件无版本号
- if (thePrefs.m_nDocHistoricVersion > 100)
- {
- if ((g_nDocVersion <= 105))// 106之前的版本
- {
- //////////////////////////////////////////////////////////////////////////
- CString strType;
- int nParanum_Inf = 0;
- int nSize_Inf = 0;
- ar >> nParanum_Inf;//读取参数数量
- ar >> nSize_Inf;
- for (int j = 0; j < nSize_Inf; j++)
- {
- TOOL_INTERFACE inf;
- for (int k = 0; k < nParanum_Inf; k++)
- {
- ar >> nPpara;
- switch (nPpara)
- {
- case 1: ar >> inf.strParentName; break;
- case 2: ar >> inf.bShow; break;//
- case 3: ar >> inf.strName; break;//
- case 4: ar >> strType; break;//
- case 5: ar >> (int&)inf.InfDirection; break;//
- case 6: ar >> inf.rect; break;//
- case 7: ar >> (int&)inf.InfType; break;//
- case 8: ar >> (int&)inf.InfWay; break;//
- default:
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE;
- }
- }
- if (strType == _T("int"))
- {
- inf.VarType = VAR_TYPE::Int_Var;
- }
- else if (strType == _T("CString"))
- {
- inf.VarType = VAR_TYPE::CString_Var;
- }
- else if (strType == _T("HImage"))
- {
- inf.VarType = VAR_TYPE::HImage_Var;
- }
- newTool.Interfaces.push_back(inf);
- }
- }
- if (g_nDocVersion > 105)// 105之后的版本
- {
- //////////////////////////////////////////////////////////////////////////
- int nParanum_Inf = 0;
- int nSize_Inf = 0;
- ar >> nParanum_Inf;//读取参数数量
- ar >> nSize_Inf;
- for (int j = 0; j < nSize_Inf; j++)
- {
- TOOL_INTERFACE inf;
- for (int k = 0; k < nParanum_Inf; k++)
- {
- ar >> nPpara;
- switch (nPpara)
- {
- case 1: ar >> inf.strParentName; break;
- case 2: ar >> inf.bShow; break;//
- case 3: ar >> inf.strName; break;//
- case 4: ar >> (int&)inf.VarType; break;//
- case 5: ar >> (int&)inf.InfDirection; break;//
- case 6: ar >> inf.rect; break;//
- case 7: ar >> (int&)inf.InfType; break;//
- case 8: ar >> (int&)inf.InfWay; break;//
- case 9: ar >> inf.nUseCount; break;//
- default:
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载失败!%s 配置文档错误! "),m_nIndex, newTool.strDll);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE;
- }
- }
- newTool.Interfaces.push_back(inf);
- }
- }
- }
- // 首先校验工具版本号以及存在与否
- // if (!g_pToolManager->ValidateTool(newTool))
- // {
- // return FALSE;
- // }
- if (newTool.rect.IsRectEmpty())
- {
- CPoint pt;
- pt.x = 25 * i + 1;
- pt.y = 25 * i + 1;
- CRect rect(pt.x, pt.y, pt.x + 100, pt.y + 100);
- newTool.rect = rect;
- }
- newTools.push_back(newTool);
- }
- // 如果校验通过,则添加工具
- for (UINT i = 0; i < newTools.size(); i++)
- {
- if (!AddNewTools(newTools[i]))
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] 在工具箱里未找到工具 %s ! "),m_nIndex, newTools[i].strName);
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE;
- }
- // 2018.10.16增加,手工调用Update
- // 否则当前未激活的任务栏由于界面没有刷新,所以不会自动更新SelTool信息
-
- UpdateTools( true );
- if (newTools[i].Type == TOOL_TYPE::TOOL_BY_PROT)
- {
- for (size_t j = 0; j < newTools[i].Interfaces.size(); j++)
- {
- TOOL_INTERFACE newInf = newTools[i].Interfaces[j];
- TOOL_INTERFACE& inf = m_SelTools[i].Interfaces[j];
- inf.bShow = newInf.bShow;
- inf.rect = newInf.rect;
- }
- }
- m_SelTools[i].nInSleep = newTools[i].nInSleep;
- m_SelTools[i].nOutSleep = newTools[i].nOutSleep;
- m_SelTools[i].hNextTool = newTools[i].hNextTool;
- UpdateTools( true);
- }
- if (g_nDocVersion > 105)
- {
- // 加载link
- nParanum = 0;//参数数量
- nSize = 0;
- m_Links.clear();
- nSize = 0;
- //LINK newLink;
- ar >> nParanum;//读取参数数量
- ar >> nSize;
- for (UINT i = 0; i < nSize; i++)
- {
- TOOL_INTERFACE source; // 连接的起点
- TOOL_INTERFACE dest; // 连接的终点
- bool bShow = true;
- for (int i = 0; i < nParanum; i++)
- {
- nPpara = 0;
- ar >> nPpara;
- switch (nPpara)
- {
- case 1: ar >> source.strParentName; break;//
- case 2: ar >> source.nIndex; break;//
- case 3: ar >> dest.strParentName; break;//
- case 4: ar >> dest.nIndex; break;//
- case 5: ar >> (int&)source.VarType; break;//
- case 6: ar >> (int&)dest.VarType; break;//
- case 7: ar >> (int&)source.InfDirection; break;//
- case 8: ar >> (int&)dest.InfDirection; break;//
- case 9: ar >> source.strName; break;//
- case 10: ar >> dest.strName; break;//
- case 11: ar >> (int&)source.InfType; break;//
- case 12: ar >> (int&)dest.InfType; break;//
- case 13: ar >> (int&)source.InfWay; break;//
- case 14: ar >> (int&)dest.InfWay; break;//
- case 15: ar >> (int&)bShow; break;//
-
- default:
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载工具连接信息失败!配置文档错误!"),m_nIndex );
- USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE;
- }
- }
- TOOL_INTERFACE* pS = GetInterfaceByInterface(source);
- TOOL_INTERFACE* pD = GetInterfaceByInterface(dest);
- BOOL bStatus = FALSE;
- if (pS != NULL &&
- pD != NULL &&
- (source.InfDirection == INF_DIRECTION::INF_OUT || source.InfDirection == INF_DIRECTION::INF_INOUT) &&
- dest.InfDirection == INF_DIRECTION::INF_IN &&
- source.VarType == dest.VarType)
- {
- bStatus = MakeLink(source, dest, bShow);
- }
- if (!bStatus)
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载工具连接信息失败%s.%s ----->>>>> %s.%s 参数不匹配 !"),m_nIndex, source.strParentName, source.strName, dest.strParentName, dest.strName); USES_CONVERSION;
- char * s_str = T2A(strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- }
- }
- }
- else
- {
- // 加载link
- nParanum = 0;//参数数量
- nSize = 0;
- m_Links.clear();
- nSize = 0;
- //LINK newLink;
- CString strType;
- ar >> nParanum;//读取参数数量
- ar >> nSize;
- for (UINT i = 0; i < nSize; i++)
- {
- TOOL_INTERFACE source; // 连接的起点
- TOOL_INTERFACE dest; // 连接的终点
- for (int i = 0; i < nParanum; i++)
- {
- nPpara = 0;
- ar >> nPpara;
- switch (nPpara)
- {
- case 1: ar >> source.strParentName; break;//
- case 2: ar >> source.nIndex; break;//
- case 3: ar >> dest.strParentName; break;//
- case 4: ar >> dest.nIndex; break;//
- case 5: ar >> strType; break;//
- case 6: ar >> strType; break;//
- case 7: ar >> (int&)source.InfDirection; break;//
- case 8: ar >> (int&)dest.InfDirection; break;//
- case 9: ar >> source.strName; break;//
- case 10: ar >> dest.strName; break;//
- case 11: ar >> (int&)source.InfType; break;//
- case 12: ar >> (int&)dest.InfType; break;//
- case 13: ar >> (int&)source.InfWay; break;//
- case 14: ar >> (int&)dest.InfWay; break;//
- default:
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载工具连接信息失败!配置文档错误!"),m_nIndex);
- //CUtility::CriticalBCGPMessageBox(strMsg);
- OUTPUT_MSG msg;
- msg.bWay = MSG_WAY::_ERROR;
- msg.strMsg = strMsg;
- USES_CONVERSION;
- char * s_str = T2A(msg.strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE;
- }
- }
- TOOL_INTERFACE* pS = GetInterfaceByInterface(source);
- TOOL_INTERFACE* pD = GetInterfaceByInterface(dest);
- BOOL bStatus = FALSE;
- if (pS != NULL &&
- pD != NULL &&
- source.InfDirection == INF_DIRECTION::INF_OUT &&
- dest.InfDirection == INF_DIRECTION::INF_IN &&
- source.VarType == dest.VarType)
- {
- bStatus = AddLink(source, dest, true);
- }
- if (!bStatus)
- {
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载工具连接信息失败%s.%s ----->>>>> %s.%s 参数不匹配 !"),m_nIndex, source.strParentName, source.strName, dest.strParentName, dest.strName);
- OUTPUT_MSG msg;
- msg.bWay = MSG_WAY::_ERROR;
- msg.strMsg = strMsg;
- USES_CONVERSION;
- char * s_str = T2A(msg.strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- }
- }
- }
- // 加载监控列表
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- nParanum = 0;//参数数量
- nSize = 0;
- TOOL& tool = m_SelTools[i];
- ar >> nParanum;//读取参数数量
- ar >> nSize;
- for (unsigned int j = 0; j < nSize; j++)
- {
- for (int i = 0; i < nParanum; i++)
- {
- nPpara = 0;
- TOOL_INTERFACE tmpInf;
- TOOL_INTERFACE& inf = tmpInf;
- if (nSize == tool.Interfaces.size())
- {
- inf = tool.Interfaces[j];
- }
- ar >> nPpara;
- switch (nPpara)
- {
- case 1: ar >> inf.nIndex; break;//
- case 2: ar >> inf.bMonitor;; break;//
- default:
- CString strMsg;
- strMsg.Format(_T("Task[%d] 加载工具监控信息失败!配置文档错误!"),m_nIndex);
- OUTPUT_MSG msg;
- msg.bWay = MSG_WAY::_ERROR;
- msg.strMsg = strMsg;
- USES_CONVERSION;
- char * s_str = T2A(msg.strMsg);
- g_Logger.Error(0, __FILE__, __LINE__, s_str);
- return FALSE;;
- }
- }
- }
- }
- UpdateTools( true);
- return TRUE;
- }
- //////////////////////////////////////////////////////
- // 当窗体激活时触发,变更当前工作窗体
- void CTaskWindow::OnSetFocus(CWnd* pOldWnd)
- {
- CBCGPStatic::OnSetFocus(pOldWnd);
- g_pTaskView->SetActiveTaskWindow(this, m_nIndex);
- }
- ///////////////////////////////////////////////////////
- // 重置所有工具执行状态
- void CTaskWindow::ResetToolExecCode()
- {
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- m_SelTools[i].nExecCode = RT_NONE;
- }
- }
- //设置接收 工具状态 数据回调函数
- void CTaskWindow::ToolStateCallback(CString strToolName, int nState, long long userParam)
- {
- CTaskWindow *pParam = (CTaskWindow*)(userParam);
- if (pParam != NULL)
- {
- pParam->OnUpdateToolState(strToolName, nState);
- }
- }
- ///////////////////////////////////////////////////////
- // Tool Log 回调
- void CTaskWindow::ToolLogCallback(CString strToolName, MSG_WAY nType, CString strMassage, long long userParam)
- {
- CMainFrame *pParam = (CMainFrame*)(userParam);
- if (pParam != NULL)
- {
- OUTPUT_MSG msg;
- msg.bWay = nType;
- msg.strMsg = strToolName + _T(" ") + strMassage;
- // pParam->ShowOutputInfo(msg, LOG);
- USES_CONVERSION;
- char * s_str = T2A(msg.strMsg);
- switch (nType)
- {
- case MSG_WAY::_INFO:
- g_Logger.Info(1, __FILE__, __LINE__, s_str);
- break;
- case MSG_WAY::_WARNING:
- g_Logger.Warn(1, __FILE__, __LINE__, s_str);
- break;
- case MSG_WAY::_ERROR:
- g_Logger.Error(1, __FILE__, __LINE__, s_str);
- break;
- default:
- g_Logger.Error(1, __FILE__, __LINE__, s_str);
- break;
- break;
- }
- }
- }
- ///////////////////////////////////////////////////////
- // Tool OnExecute 回调
- void CTaskWindow::ToolOnExecuteCallback(CString strToolName, long long userParam)
- {
- CTaskWindow *pParam = (CTaskWindow*)(userParam);
- if (pParam != NULL)
- {
- if (!strToolName.IsEmpty())
- {
- pParam->OnExecuteTool(strToolName);
- }
- }
- }
- ///////////////////////////////////////////////////////
- // ToolBusy 回调
- void CTaskWindow::ToolBusyCallback(CString strToolName, int nState, CString strMassage, long long userParam)
- {
- CTaskWindow *pParam = (CTaskWindow*)(userParam);
- if (pParam != NULL)
- {
- if (!strToolName.IsEmpty())
- {
- }
- }
- }
- //////////////////////////////////////////////////////////////
- // 清空Watch
- void CTaskWindow::WatchClear()
- {
- WATCH::iterator it = mWatch.begin();
- for (; it != mWatch.end(); it++)
- {
- if (it->second != NULL)
- {
- it->second->DestroyWindow();
- RELEASE_BUFFER(it->second);
- }
- }
- mWatch.clear();
- }
- /////////////////////////////////////////////////////////
- // 更新工具状态
- void CTaskWindow::OnUpdateToolState(CString strToolName, int nState)
- {
- // 重置所有工具执行状态
- ResetToolExecCode();
- // 查找工具
- for (unsigned int i = 0; i < m_SelTools.size(); i++)
- {
- TOOL& tool = m_SelTools[i];
- if (tool.strShowName == strToolName)
- {
- tool.nToolState = nState;
- //m_wndTree.Invalidate(TRUE);
- }
- }
- }
- void CTaskWindow::OnUpdate(CCmdUI* pCmdUI)
- {
- if (g_nRunningState != 0)
- {
- //g_pMainFrame->PopupMessage(MSG_WAY::_WARNING, _T("操作被禁止"), _T("运行中,禁止该操作....."));
- pCmdUI->Enable(false);
- return;
- }
- pCmdUI->Enable(true);
- }
- void CTaskWindow::OnBnClickedUp()
- {
- m_editor.Down();
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedDown()
- {
- m_editor.Up();
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedFront()
- {
- m_editor.Bottom();
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedBottom()
- {
- m_editor.Front();
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedLeftAlign()
- {
- m_editor.LeftAlignSelected();
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedRightAlign()
- {
- m_editor.RightAlignSelected();
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedTopAlign()
- {
- m_editor.TopAlignSelected();
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedBottomAlign()
- {
- m_editor.BottomAlignSelected();
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedZoomIn()
- {
- // m_editor.SetZoom(m_editor.GetZoom() + m_editor.GetZoomFactor() * 10);
- }
- void CTaskWindow::OnBnClickedZoomOut()
- {
- // m_editor.SetZoom(m_editor.GetZoom() - m_editor.GetZoomFactor() * 10);
- }
- void CTaskWindow::OnBnClickedZoomZero()
- {
- m_editor.SetZoom(1.0);
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedSettings()
- {
- CString str;
- this->GetWindowText(str);
- CTaskSettings dlg;
- dlg.m_TaskInfo.bTaskMode = m_TaskMode;
- dlg.m_TaskInfo.nSleepTime = m_nSleepTime;
- dlg.m_TaskInfo.strTaskName = m_strTaskName;
- dlg.m_nWindowWidth = m_editor.GetVirtualSize().cx;
- dlg.m_nWindowHeight = m_editor.GetVirtualSize().cy;
- dlg.m_gridWidth = m_editor.GetGridSize().cx;
- dlg.m_gridHeight = m_editor.GetGridSize().cy;
- m_editor.GetMargins(dlg.m_marginLeft, dlg.m_marginTop, dlg.m_marginRight, dlg.m_marginBottom);
- dlg.m_pTaskWindow = (LPVOID)this;
- if (dlg.DoModal() == IDOK)
- {
- m_TaskMode = dlg.m_TaskInfo.bTaskMode;
- m_nSleepTime = dlg.m_TaskInfo.nSleepTime;
- m_strTaskName = dlg.m_TaskInfo.strTaskName;
- m_editor.SetGridSize(CSize(dlg.m_gridWidth, dlg.m_gridHeight));
- m_editor.SetVirtualSize(CSize(dlg.m_nWindowWidth, dlg.m_nWindowHeight));
- m_editor.SetMargins(dlg.m_marginLeft, dlg.m_marginTop, dlg.m_marginRight, dlg.m_marginBottom);
- m_editor.RedrawWindow();
- //保存配置好的参数到本地
- m_editor.GetMargins(m_nMarginLeft, m_nMarginTop, m_nMarginRight, m_nMarginBottom);
- g_pTaskView->SetTabText(m_nIndex, m_strTaskName);
- }
- UpdateTools();
- m_editor.RedrawWindow();
- }
- void CTaskWindow::OnBnClickedRunOnce()
- {
- DWORD id;
- HANDLE hTread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&CTaskWindow::SysRunOce, this, 0, &id);
- CloseHandle(hTread);
- }
- void CTaskWindow::SysRunOce(LPVOID pParam)
- {
- CTaskWindow* pThis = (CTaskWindow*)pParam;
- if (g_nRunningState != 0)
- {
- g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Error [State:%d]", g_nRunningState);
- return;
- }
- g_nRunningState = 2;
- // 清空当前任务栏中所有任务的执行状态
- pThis->ResetToolExecCode();
- SetEvent(pThis->m_hExecuteEven);
- ResetEvent(pThis->m_hExecuteEven);
- g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Start [%d]", g_nRunningState);
- WaitForSingleObject(pThis->m_hDoneEven, INFINITE);
- ResetEvent(pThis->m_hDoneEven);
- g_nRunningState = 0;
- g_Logger.Info(0, __FILE__, __LINE__, "CTaskWindow::SysRunOce() Done [%d]", g_nRunningState);
- }
- void CTaskWindow::OnBnClickedButtonCopy()
- {
- // TODO: 在此添加控件通知处理程序代码
- TOOL* pTool = this->GetToolByHandle(m_Item);
- if (pTool != NULL)
- {
- CSharedFile memFile;
- CArchive ar(&memFile, CArchive::store | CArchive::bNoFlushOnDelete);
- ar << pTool->strName;
- ar << pTool->strShowName;
- pTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion);
- ar << pTool->strName;
-
- ar.Flush();
- HGLOBAL hData = memFile.Detach();
- if (OpenClipboard())
- {
- ::SetClipboardData(g_cfObjectFormat, hData);
- CloseClipboard();
- USES_CONVERSION;
- CString str;
- str.Format(_T("Task[%d] Cope %s Data OK "),m_nIndex, pTool->strShowName);
- char * s_str = T2A(str);
- g_Logger.Info(0, __FILE__, __LINE__, s_str);
- }
- }
- }
- void CTaskWindow::OnBnClickedButtonPaste()
- {
- // TODO: 在此添加控件通知处理程序代码
- if (OpenClipboard())
- {
- HANDLE hData = ::GetClipboardData(g_cfObjectFormat);
- if (hData != NULL)
- {
- //if (BCGPMessageBox(_T("是否粘贴数据 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Paste Data .....")) == IDYES)
- {
- CSharedFile memFile;
- memFile.SetHandle(hData, FALSE);
- CArchive ar(&memFile, CArchive::load);
- CString str, strToolName, strShowName;
- ar >> strToolName;
- ar >> strShowName;
- TOOL* pSourceTool = GetToolByShowName(strShowName);// 先择的模块(工具实体模块)
- if (pSourceTool != NULL)
- {
-
- TOOL newTool;
- newTool.strName = strToolName;
- newTool.strShowName = strToolName/* + _T("Copy")*/;
- newTool.rect = pSourceTool->rect;
- newTool.rect.TopLeft().x += 10;
- newTool.rect.TopLeft().y -= 30;
- CString strShowName;
- AddNewTools2(newTool, &strShowName);
- UpdateTools();
- TOOL* pNewTool = GetToolByShowName(strShowName);
- if (pNewTool != NULL)
- {
- pNewTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion);
- ar >> strToolName;
- USES_CONVERSION;
- str.Format(_T("Paste %s Data OK [%s]"), pNewTool->strShowName, strToolName);
- char * s_str = T2A(str);
- g_Logger.Info(0, __FILE__, __LINE__, s_str);
- }
- }
- ar.Close();
- memFile.Detach();
- EmptyClipboard();// 清空粘贴板
- }
-
- }
-
- CloseClipboard();
- }
-
- // TOOL* pTool = this->GetToolByHandle(m_Item);
- // if (pTool != NULL)
- // {
- // if (OpenClipboard())
- // {
- // HANDLE hData = ::GetClipboardData(g_cfObjectFormat);
- // if (hData != NULL)
- // {
- //
- // CSharedFile memFile;
- // memFile.SetHandle(hData, FALSE);
- // CArchive ar(&memFile, CArchive::load);
- // CString str, strToolName;
- // ar >> strToolName;
- // if (strToolName == pTool->strName)
- // {
- // if (BCGPMessageBox(_T("是否粘贴数据 ? "), MB_YESNO | MB_ICONQUESTION, 0, NULL, _T("Paste Data .....")) == IDYES)
- // {
- // pTool->pDllPtr->Serialize(ar, g_nExeVersion, g_nDocVersion);
- //
- // ar >> strToolName;
- //
- // USES_CONVERSION;
- // str.Format(_T("Paste %s Data OK [%s]"), pTool->strShowName , strToolName);
- // char * s_str = T2A(str);
- // g_Logger.Info(0, __FILE__, __LINE__, s_str);
- // }
- // }
- // else
- // {
- // USES_CONVERSION;
- // str.Format(_T("Paste %s Data Error SourceTool [%s]"), pTool->strShowName, strToolName);
- // char * s_str = T2A(str);
- // g_Logger.Error(0, __FILE__, __LINE__, s_str);
- // }
- // ar.Close();
- // memFile.Detach();
- // EmptyClipboard();// 清空粘贴板
- // }
- // else
- // {
- // USES_CONVERSION;
- // CString str;
- // str.Format(_T("Paste %s Data Error Dara isNULL"), pTool->strShowName);
- // char * s_str = T2A(str);
- // g_Logger.Error(0, __FILE__, __LINE__, s_str);
- // }
- // CloseClipboard();
- // }
- // }
- }
- void CTaskWindow::SortProtToolID(const TOOL* pSourceTool, const TOOL* pDestTool)
- {
- if (pDestTool != NULL && pSourceTool != NULL)
- {
- CDiagramEntityContainer* objs = static_cast<CDiagramEntityContainer*> (m_editor.GetDiagramEntityContainer());
- if (objs)
- {
- UINT nIndex = 0;
- for (UINT i = 0; i < objs->GetSize(); i++)
- {
- CFunctionBlock* obj = (CFunctionBlock*)objs->GetAt(i);
- if (obj->Tools.strShowName == pSourceTool->strShowName)
- {
- m_editor.SetSelectedObject(obj);
- }
- }
- }
- {
- int nToolID = pDestTool->nToolID;
- int nProtID = pSourceTool->nToolID;
- if (nProtID > nToolID)
- {
- for (int j = 0; j < (nProtID - nToolID); j++)
- {
- OnBnClickedUp();
- }
- }
- }
- }
- }
- void CTaskWindow::ShowNodeWatch(/*const*/ TOOL_INTERFACE* pInf)
- {
- if ( pInf != NULL )
- {
-
- WATCH::iterator it = mWatch.begin();
- //先遍历,看该节点是否创建过
- BOOL bFind = FALSE;
- for (; it != mWatch.end(); )
- {
- if (it->first == pInf)
- {
- bFind = TRUE;
- break;
- }
- ++it;
- }
- if (!bFind)
- {
- CNodeWatchDlg* pDlg = NULL;
- pDlg = new CNodeWatchDlg(this);
- pDlg->Create(IDD_NODEWATCHDLG, g_pMainFrame->GetActiveView());
- pDlg->strName = pInf->strName;
- pDlg->strParentName = pInf->strParentName;
- mWatch[pInf] = pDlg;
- }
- if (mWatch[pInf] != NULL)
- {
- mWatch[pInf]->ShowWindow(SW_SHOW);
- CString str;
- str.Format(_T("监视:%s [ %s ]"), pInf->strParentName, pInf->strName);
- mWatch[pInf]->SetWindowTextW(str);
- }
- }
- }
|