// EdIRBeha.cpp : implementation file // #include "stdafx.h" #include "Defines.hpp" #ifdef D_ED_IR_ACTIVE #include #include "EdIRBeha.hpp" #include "EdIRRVw.hpp" #include "EdIRBVw.hpp" #include "EdIRFrm.hpp" #include "EdIRBNam.hpp" #include "EdIRStrg.hpp" #include "EdIRBeEn.hpp" #include "EdIRIRD.hpp" #include "EdIRBeEn.hpp" #include "EdIR2Eng.hpp" #include "ai_intf.hpp" #include "ACP_Base.h" #include "ITF.h" #include "IncMEC.h" #include "incAI.h" #include "_Actors.hpp" #include "_AInterf.hpp" #include "EdIRBis.hpp" #include "x:\cpa\main\inc\_EditID.h" #include "incTUT.h" //ANNECY CB #include "EDIRGlob.hpp" //END ANNECY // BEGIN CPA2 Cristi Petrescu 98-03- #include "EdIRMacL.hpp" extern CPA_EdIR_MacroList g_clMacroList; // END CPA2 Cristi Petrescu 98-03- //Stefan Dumitrean 9-06-98 #include "Edirflx.hpp" //End Stefan Dumitrean #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // class CPA_EdIR_Behaviour ///////////////////////////////////////////////////////////////////////////// BEGIN_MESSAGE_MAP(CPA_EdIR_Behaviour, CButton) //{{AFX_MSG_MAP(CPA_EdIR_Behaviour) ON_WM_MOUSEMOVE() ON_WM_LBUTTONDOWN() ON_WM_RBUTTONUP() ON_WM_KEYUP() ON_WM_KEYDOWN() ON_WM_CHAR() ON_WM_TIMER() //}}AFX_MSG_MAP ON_COMMAND(ID_IR_BEHAVIOUR_DELETE_BEHAVIOUR,m_fn_vOnDeleteBehaviour) ON_COMMAND(ID_IR_BEHAVIOUR_RENAME_BEHAVIOUR,m_fn_vOnRenameBehaviour) END_MESSAGE_MAP() /****************************************************************************/ CPA_EdIR_Behaviour::CPA_EdIR_Behaviour(CPA_EdIR_View *p_clIAView,BOOL bDeclaration) { m_pclIAViewRules =p_clIAView; m_eMoveSizeType =MOVE_SIZE_NONE; m_lOffsetX =0; m_lOffsetY =0; m_bIAmActive =TRUE; m_bDeclaration =bDeclaration; m_bHasBeenModified =FALSE; m_pclMainBehaviour =NULL; m_bIntermediateCodeListIsGood =FALSE; //ANNECY CB m_bFirstActivate = TRUE; m_lErrorIndex = -1; m_bIAmActive = FALSE; //END ANNECY m_bOldMacro = FALSE; } /****************************************************************************/ CPA_EdIR_Behaviour::~CPA_EdIR_Behaviour() { /* POSITION pos=m_clListOfLinkBehaviours.GetHeadPosition(); while(pos!=NULL) delete m_clListOfLinkBehaviours.GetNext(pos); m_clListOfLinkBehaviours.RemoveAll();*/ m_clListOfDependentBehaviours.RemoveAll(); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vSetMainBehaviour(CPA_EdIR_MainBehaviour *pclMainBehaviour) { m_pclMainBehaviour=pclMainBehaviour; m_fn_vRegisterInTUT(); } /****************************************************************************/ CPA_EdIR_MainBehaviour *CPA_EdIR_Behaviour::m_fn_pclGetMainBehaviour() { return m_pclMainBehaviour; } ///////////////////////////////////////////////////////////////////////////// // CPA_Behaviour message handlers /****************************************************************************/ BOOL CPA_EdIR_Behaviour::PreCreateWindow(CREATESTRUCT& cs) { cs.style|=BS_OWNERDRAW; return CButton::PreCreateWindow(cs); } /****************************************************************************/ BOOL CPA_EdIR_Behaviour::Create(LPCTSTR lpszCaption,DWORD dwStyle,const RECT& rect,CWnd* pParentWnd,UINT nID) { BOOL bRes=CButton::Create(lpszCaption,dwStyle,rect,pParentWnd,nID); if(bRes) { //Stefan Dumitrean 8-06-98 (new scroll) // m_clEditCtrl.Create(WS_CHILD|(dwStyle & WS_VISIBLE)|ES_MULTILINE|ES_WANTRETURN, // CRect(12,0,10000,40000), // m_pclIAViewRules, // 123456789); m_clEditCtrl.Create(WS_CHILD|(dwStyle & WS_VISIBLE)|ES_MULTILINE|ES_WANTRETURN| ES_AUTOHSCROLL|ES_AUTOVSCROLL|WS_HSCROLL|WS_VSCROLL, CRect(12,0,600,200), m_pclIAViewRules, 123456789); //End Stefan Dumitrean 8-06-98 m_clFont.CreateFont(12,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_STRING_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY, DEFAULT_PITCH,"Arial"); SetFont(&m_clFont); CClientDC cDc(this); cDc.SelectObject(&m_clFont); CSize clRuleSize=cDc.GetTextExtent(lpszCaption); CRect cr(rect); cr.right=cr.left+clRuleSize.cx+20; MoveWindow(cr,FALSE); SetClassLong(m_hWnd,GCL_HCURSOR,0L); } return bRes; } /****************************************************************************/ void CPA_EdIR_Behaviour::OnDestroy() { ////////////// ////////////// //Registers for TUT Module TUT_M_vGetTutDll(); TUT_M_vUnregisterControl(m_clEditCtrl.m_hWnd); //End of Register for TUT Module CButton::OnDestroy(); } /****************************************************************************/ BOOL CPA_EdIR_Behaviour::ShowWindow(int nCmdShow) { if(m_bIAmActive) m_clEditCtrl.ShowWindow(nCmdShow); return CButton::ShowWindow(nCmdShow); } /****************************************************************************/ #define C_ACTIVE_ZONE_HEIGHT 10 #define C_ACTIVE_ZONE_WIDTH 10 #define C_HALF_ACTIVE_ZONE_HEIGHT C_ACTIVE_ZONE_HEIGHT/2 #define C_HALF_ACTIVE_ZONE_WIDTH C_ACTIVE_ZONE_WIDTH/2 /****************************************************************************/ void CPA_EdIR_Behaviour::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC *cdc; cdc=cdc->FromHandle(lpDrawItemStruct->hDC); CRect cr; GetWindowRect(cr); CRect crBoundingBox=CRect(C_HALF_ACTIVE_ZONE_WIDTH,C_HALF_ACTIVE_ZONE_HEIGHT, cr.Width()-C_HALF_ACTIVE_ZONE_WIDTH,cr.Height()-C_HALF_ACTIVE_ZONE_HEIGHT); //Draws Background if(m_bIAmActive) cdc->FillSolidRect(crBoundingBox,RGB(200,50,50)); else cdc->FillSolidRect(crBoundingBox,RGB(0,150,200)); //Draws Border cdc->MoveTo(C_HALF_ACTIVE_ZONE_WIDTH,C_HALF_ACTIVE_ZONE_HEIGHT); cdc->LineTo(cr.Width()-C_HALF_ACTIVE_ZONE_WIDTH,C_HALF_ACTIVE_ZONE_HEIGHT); cdc->LineTo(cr.Width()-C_HALF_ACTIVE_ZONE_WIDTH,cr.Height()-C_HALF_ACTIVE_ZONE_HEIGHT); cdc->LineTo(C_HALF_ACTIVE_ZONE_WIDTH,cr.Height()-C_HALF_ACTIVE_ZONE_HEIGHT); cdc->LineTo(C_HALF_ACTIVE_ZONE_WIDTH,C_HALF_ACTIVE_ZONE_HEIGHT); //Draws Title CString csText; GetWindowText(csText); cdc->DrawText(csText,crBoundingBox,DT_SINGLELINE|DT_VCENTER|DT_CENTER); //Draws Dependencies m_fn_vDrawDependencies(RGB(0,0,0)); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vDrawDependency(CPA_EdIR_Behaviour *pclBehaviourEnd,CString csText,COLORREF color) { //Gets start behaviour position CRect crStart; GetWindowRect(crStart); GetParent()->ScreenToClient(crStart); CPoint cpStart=crStart.CenterPoint(); //Gets end behaviour position CRect crEnd; pclBehaviourEnd->GetWindowRect(crEnd); GetParent()->ScreenToClient(crEnd); CPoint cpEnd=crEnd.CenterPoint(); //Draws dependency CClientDC cParentDc(GetParent()); ((CPA_EdIR_DiagView *)GetParent())->m_fn_vClipControls(&cParentDc); CPen clPen(PS_SOLID,1,color); CPen *pold=cParentDc.SelectObject(&clPen); //Draws arrow double fUx=cpEnd.x-cpStart.x; double fUy=cpEnd.y-cpStart.y; double fux=11*fUx/20; double fuy=11*fUy/20; double fNormeU=sqrt(fUx*fUx+fUy*fUy); double fVx=fux-4*fUy/fNormeU; double fVy=fuy+4*fUx/fNormeU; double fMVx=fux+4*fUy/fNormeU; double fMVy=fuy-4*fUx/fNormeU; double fPVx=16*fUx/fNormeU+fux; double fPVy=16*fUy/fNormeU+fuy; CPoint a_cpPoly[3]; a_cpPoly[0]=CPoint(int(fVx+cpStart.x),int(fVy+cpStart.y)); a_cpPoly[1]=CPoint(int(fPVx+cpStart.x),int(fPVy+cpStart.y)); a_cpPoly[2]=CPoint(int(fMVx+cpStart.x),int(fMVy+cpStart.y)); cParentDc.Polyline(a_cpPoly,3); //Draws line cParentDc.MoveTo(cpStart); cParentDc.LineTo(cpEnd); cParentDc.SelectObject(pold); //Draws text cParentDc.SelectObject(&m_clFont); CSize clRuleSize=cParentDc.GetTextExtent(csText); CRect crRuleRect; crRuleRect.left=max(max(a_cpPoly[0].x,a_cpPoly[1].x),a_cpPoly[2].x)+2; crRuleRect.top=min(min(a_cpPoly[0].y,a_cpPoly[1].y),a_cpPoly[2].y); crRuleRect.right=crRuleRect.left+clRuleSize.cx; crRuleRect.bottom=crRuleRect.top+clRuleSize.cy; cParentDc.SetBkMode(TRANSPARENT); cParentDc.SetTextColor(color); cParentDc.DrawText(csText,crRuleRect,DT_CENTER|DT_VCENTER); } /****************************************************************************/ BOOL CPA_EdIR_Behaviour::m_fn_bDependencyIsDrawable(CPA_BaseObject *pclObject) { if(pclObject->fn_bIsOfType(C_szIABehaviourTypeName)) { CPA_EdIR_DiagView *pclDiagView=(CPA_EdIR_DiagView *)GetParent(); CPA_EdIR_MainBehaviour *pclMainBehaviour=(CPA_EdIR_MainBehaviour *)pclObject; return pclDiagView->m_fn_bIsInCurrentList(pclMainBehaviour); } else return FALSE; } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vDrawDependencies(COLORREF color) { if(m_pclMainBehaviour!=NULL) { //Draws dependencies POSITION pos=m_pclMainBehaviour->m_clListOfDependencies.GetHeadPosition(); while(pos!=NULL) { CPA_BaseObject *pclChild=m_pclMainBehaviour->m_clListOfDependencies.GetAt(pos); if(m_fn_bDependencyIsDrawable(pclChild)) { CPA_EdIR_MainBehaviour *pclMainBehaviour=(CPA_EdIR_MainBehaviour *)pclChild; if(pclMainBehaviour->m_pclBehaviour!=NULL) m_fn_vDrawDependency(pclMainBehaviour->m_pclBehaviour,"",color); } m_pclMainBehaviour->m_clListOfDependencies.GetNext(pos); } //Draws dependencies CList clFatherList; g_oCoherenceManager.m_fn_iGetFatherList(m_pclMainBehaviour,&clFatherList); pos=clFatherList.GetHeadPosition(); while(pos!=NULL) { CPA_BaseObject *pclChild=clFatherList.GetAt(pos); if(m_fn_bDependencyIsDrawable(pclChild)) { CPA_EdIR_MainBehaviour *pclMainBehaviour=(CPA_EdIR_MainBehaviour *)pclChild; //Looks for 'this' in pclFatherList /*POSITION poslink=pclMainBehaviour->m_clListOfDependencies.GetHeadPosition(); BOOL bFound=FALSE; CString csText; while(poslink!=NULL && !bFound) { CPA_EdIR_MainBehaviour *pclChild=pclMainBehaviour->m_clListOfDependencies.GetAt(poslink); if(pclChild==m_pclMainBehaviour) { bFound=TRUE; csText=pclChild->m_csRules; } else pclMainBehaviour->m_clListOfDependencies.GetNext(poslink); } if(bFound)*/ if(pclMainBehaviour->m_pclBehaviour!=NULL) pclMainBehaviour->m_pclBehaviour->m_fn_vDrawDependency(this,"",color); } clFatherList.GetNext(pos); } } } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vDrawDependencies() { if(m_pclMainBehaviour!=NULL) { //Draws dependencies POSITION pos=m_pclMainBehaviour->m_clListOfDependencies.GetHeadPosition(); while(pos!=NULL) { CPA_BaseObject *pclChild=m_pclMainBehaviour->m_clListOfDependencies.GetAt(pos); if(m_fn_bDependencyIsDrawable(pclChild)) { CPA_EdIR_MainBehaviour *pclMainBehaviour=(CPA_EdIR_MainBehaviour *)pclChild; if(pclMainBehaviour->m_pclBehaviour!=NULL) m_fn_vDrawDependency(pclMainBehaviour->m_pclBehaviour,"",RGB(0,0,0)); } m_pclMainBehaviour->m_clListOfDependencies.GetNext(pos); } } } /****************************************************************************/ void CPA_EdIR_Behaviour::OnMouseMove(UINT nFlags, CPoint point) { CPoint cp=point; ClientToScreen(&cp); GetParent()->ScreenToClient(&cp); CPoint cpOffset=((CScrollView *)GetParent())->GetScrollPosition(); CRect crParentSize; GetParent()->GetClientRect(crParentSize); CSize clParentViewSize=((CScrollView *)GetParent())->GetTotalSize(); //AutoScroll CPoint cpDestPoint=cpOffset; if(cp.x<0) cpDestPoint.x-=10; if(cp.y<0) cpDestPoint.y-=10; if(cp.x>crParentSize.Width()) cpDestPoint.x+=10; if(cp.y>crParentSize.Height()) cpDestPoint.y+=10; if(cpDestPoint!=cpOffset) ((CScrollView *)GetParent())->ScrollToPosition(cpDestPoint); cp+=cpOffset; if(m_eMoveSizeType!=MOVE_SIZE_MOVE) { if(cp.x<0) point.x-=cp.x; if(cp.y<0) point.y-=cp.y; if(cp.x>clParentViewSize.cx) point.x-=cp.x-clParentViewSize.cx; if(cp.y>clParentViewSize.cy) point.y-=cp.y-clParentViewSize.cy; } else { CRect clBtSize; GetClientRect(clBtSize); if(cp.x-m_lOffsetX<0) point.x-=cp.x-m_lOffsetX; if(cp.y-m_lOffsetY<0) point.y-=cp.y-m_lOffsetY; if(cp.x+clBtSize.Width()-m_lOffsetX>clParentViewSize.cx) point.x-=cp.x-clParentViewSize.cx+clBtSize.Width()-m_lOffsetX; if(cp.y+clBtSize.Height()-m_lOffsetY>clParentViewSize.cy) point.y-=cp.y-clParentViewSize.cy+clBtSize.Height()-m_lOffsetY; } if(nFlags & MK_LBUTTON) { CClientDC cParentDc(GetParent()); m_fn_vDrawDependencies(cParentDc.GetPixel(0,0)); } CRect cr; GetWindowRect(cr); GetParent()->ScreenToClient(cr); /* if(point.xLoadStandardCursor(IDC_SIZENWSE)); else if(point.x>cr.Width()-C_ACTIVE_ZONE_WIDTH && point.yLoadStandardCursor(IDC_SIZENESW)); else if(point.xcr.Height()-C_ACTIVE_ZONE_HEIGHT) ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENESW)); else if(point.x>cr.Width()-C_ACTIVE_ZONE_WIDTH && point.y>cr.Height()-C_ACTIVE_ZONE_HEIGHT) ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENWSE)); else if(point.ycr.Height()-C_ACTIVE_ZONE_HEIGHT) ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS)); else if(point.xcr.Width()-C_ACTIVE_ZONE_WIDTH) ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE)); else*/ ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEALL)); switch(m_eMoveSizeType) { /* case MOVE_SIZE_TOP: if(nFlags & MK_LBUTTON) { if(point.yC_ACTIVE_ZONE_HEIGHT) MoveWindow(cr.left,cr.top, cr.Width(),point.y+C_HALF_ACTIVE_ZONE_HEIGHT); } else m_eMoveSizeType=MOVE_SIZE_NONE; break; case MOVE_SIZE_LEFT: if(nFlags & MK_LBUTTON) { if(point.xC_ACTIVE_ZONE_WIDTH) MoveWindow(cr.left,cr.top, point.x+C_HALF_ACTIVE_ZONE_WIDTH,cr.Height()); } else m_eMoveSizeType=MOVE_SIZE_NONE; break; case MOVE_SIZE_LEFT_TOP: if(nFlags & MK_LBUTTON) { if(point.xC_ACTIVE_ZONE_WIDTH && point.yC_ACTIVE_ZONE_HEIGHT) MoveWindow(point.x-C_HALF_ACTIVE_ZONE_WIDTH+cr.left,cr.top, cr.Width()-point.x+C_HALF_ACTIVE_ZONE_WIDTH,point.y+C_HALF_ACTIVE_ZONE_HEIGHT); } else m_eMoveSizeType=MOVE_SIZE_NONE; break; case MOVE_SIZE_RIGHT_BOTTOM: if(nFlags & MK_LBUTTON) { if(point.x>C_ACTIVE_ZONE_WIDTH && point.y>C_ACTIVE_ZONE_HEIGHT) MoveWindow(cr.left,cr.top, point.x+C_HALF_ACTIVE_ZONE_WIDTH,point.y+C_HALF_ACTIVE_ZONE_HEIGHT); } else m_eMoveSizeType=MOVE_SIZE_NONE; break;*/ case MOVE_SIZE_MOVE: if(nFlags & MK_LBUTTON) { POINT p=point; ClientToScreen(&p); GetParent()->ScreenToClient(&p); MoveWindow(p.x-m_lOffsetX,p.y-m_lOffsetY, cr.Width(),cr.Height()); } else { m_lOffsetX=0; m_lOffsetY=0; m_eMoveSizeType=MOVE_SIZE_NONE; } break; default: break; } if(m_eMoveSizeType!=MOVE_SIZE_NONE) InvalidateRect(NULL); CButton::OnMouseMove(nFlags, point); if(nFlags & MK_LBUTTON) SetCapture(); else ReleaseCapture(); GetWindowRect(cr); GetParent()->ScreenToClient(cr); point.x+=cr.left; point.y+=cr.top; ((CPA_EdIR_DiagView *)GetParent())->OnMouseMove(nFlags,point); } /****************************************************************************/ void CPA_EdIR_Behaviour::OnLButtonDown(UINT nFlags, CPoint point) { CRect cr; GetWindowRect(cr); GetParent()->ScreenToClient(cr); if(m_eMoveSizeType==MOVE_SIZE_NONE) { /* if(point.xLoadStandardCursor(IDC_SIZENWSE)); m_eMoveSizeType=MOVE_SIZE_LEFT_TOP; } else if(point.x>cr.Width()-C_ACTIVE_ZONE_WIDTH && point.yLoadStandardCursor(IDC_SIZENESW)); m_eMoveSizeType=MOVE_SIZE_RIGHT_TOP; } else if(point.xcr.Height()-C_ACTIVE_ZONE_HEIGHT) { ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENESW)); m_eMoveSizeType=MOVE_SIZE_LEFT_BOTTOM; } else if(point.x>cr.Width()-C_ACTIVE_ZONE_WIDTH && point.y>cr.Height()-C_ACTIVE_ZONE_HEIGHT) { ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENWSE)); m_eMoveSizeType=MOVE_SIZE_RIGHT_BOTTOM; } else if(point.ycr.Height()-C_ACTIVE_ZONE_HEIGHT) { ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZENS)); if(point.ycr.Width()-C_ACTIVE_ZONE_WIDTH) { ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_SIZEWE)); if(point.xLoadStandardCursor(IDC_SIZEALL)); m_lOffsetX=point.x; m_lOffsetY=point.y; m_eMoveSizeType=MOVE_SIZE_MOVE; } } BringWindowToTop(); InvalidateRect(NULL); CButton::OnLButtonDown(nFlags, point); ((CPA_EdIR_DiagView *)GetParent())->m_fn_vOldActiveBehaviourHasChanged(this); } /****************************************************************************/ void CPA_EdIR_Behaviour::OnRButtonUp(UINT nFlags, CPoint point) { CRect cr; GetWindowRect(cr); CMenu Menu; Menu.LoadMenu(IDR_IR_MENU_POPUP_DIAGVIEW); CMenu *SousMenu=Menu.GetSubMenu(1); if(m_bDeclaration || !m_clListOfDependentBehaviours.IsEmpty()) { SousMenu->EnableMenuItem(ID_IR_BEHAVIOUR_RENAME_BEHAVIOUR,MF_GRAYED|MF_BYCOMMAND); SousMenu->EnableMenuItem(ID_IR_BEHAVIOUR_DELETE_BEHAVIOUR,MF_GRAYED|MF_BYCOMMAND); } ////////////// ////////////// //Registers for TUT Module TUT_M_vGetTutDll(); TUT_M_vRegisterMenu(m_hWnd,SousMenu->m_hMenu,cr.left+point.x,cr.top+point.y); //End of Register for TUT Module ////////////// SousMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,cr.left+point.x,cr.top+point.y,this); SousMenu->DestroyMenu(); Menu.DestroyMenu(); } /****************************************************************************/ void CPA_EdIR_Behaviour::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CButton::OnKeyDown(nChar, nRepCnt, nFlags); ((CPA_EdIR_DiagView *)GetParent())->OnKeyDown(nChar, nRepCnt, nFlags); } /****************************************************************************/ void CPA_EdIR_Behaviour::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { CButton::OnKeyUp(nChar, nRepCnt, nFlags); ((CPA_EdIR_DiagView *)GetParent())->OnKeyUp(nChar, nRepCnt, nFlags); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vOnDeleteBehaviour() { ReleaseCapture(); ((CPA_EdIR_DiagView *)GetParent())->m_fn_vDeleteBehaviour(this); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vOnRenameBehaviour() { m_fn_vRenameBehaviour(); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vRenameBehaviour() { CString csName; GetWindowText(csName); CPA_EdIR_DlgNewBehaviourName clNewName(csName); if(clNewName.DoModal()==IDOK && ((CPA_EdIR_DiagView *)GetParent())->m_fn_bNameAlreadyExists(clNewName.m_csNewName)==FALSE) { ((CPA_EdIR_DiagView *)GetParent())->m_fn_vAskForRenamingBehaviour(this,csName,clNewName.m_csNewName); } } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vActivate(BOOL bActive) { if (!g_pclAIInterface->m_bIsProcessing) { AfxGetApp()->DoWaitCursor(1); ::SetCapture(g_pclAIInterface->m_pclIRMainFrame->m_hWnd); } if(bActive && !m_bIAmActive) { m_bIAmActive=bActive; //ANNECY CB if((m_bFirstActivate) && (gbFirstShowBrain == FALSE)) { CString csMsgBase="Updating colors... "; fn_vDisplayInfoInStatusBar(csMsgBase,C_STATUS_NORMAL); m_clEditCtrl.mb_CanDefault = FALSE; //BEGIN ROMTEAM Cristi Petrescu 98-05- //m_clEditCtrl . m_fn_vHideNonExecutedLines (& m_pclMainBehaviour -> m_clDebugInfoList); m_clEditCtrl.m_fn_vColorText(0,m_clEditCtrl.GetTextLength()); //END ROMTEAM Cristi Petrescu 98-05- m_clEditCtrl.mb_CanDefault = TRUE; m_bFirstActivate = FALSE; m_clEditCtrl.SetSel(0, 0); //Stefan Dumitrean 8-06-98 (new scroll) // ((CScrollView *)m_clEditCtrl.GetParent())->ScrollToPosition(CPoint(0,0)); m_clEditCtrl.ScrollToPosition(CPoint(0,0)); // CPoint clPos=m_clEditCtrl.GetCharPos(m_clEditCtrl.GetTextLength()-1); // ((CScrollView *)m_clEditCtrl.GetParent())->SetScrollSizes(MM_TEXT,CSize(10000,clPos.y+m_clEditCtrl.m_clFontSize.cy+m_clEditCtrl.m_lVScrollHeight)); //End Stefan Dumitrean 8-06-98 CString csMsg=csMsgBase+"OK"; fn_vDisplayInfoInStatusBar(csMsg,C_STATUS_NORMAL); } //END ANNECY m_clEditCtrl.ShowWindow(SW_SHOW); InvalidateRect(NULL); } else if(!bActive && m_bIAmActive) { m_bIAmActive=bActive; m_clEditCtrl.ShowWindow(SW_HIDE); InvalidateRect(NULL); } if (!g_pclAIInterface->m_bIsProcessing) { AfxGetApp()->DoWaitCursor(-1); ReleaseCapture(); } } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vSetRules(CString csRules) { m_clEditCtrl.m_fn_vSetText(csRules); } /****************************************************************************/ CString CPA_EdIR_Behaviour::m_fn_csGetRules() { return m_clEditCtrl.m_fn_csGetText(); } /****************************************************************************/ CString CPA_EdIR_Behaviour::m_fn_csGetName() { CString csName; GetWindowText(csName); return csName; } /****************************************************************************/ CRect CPA_EdIR_Behaviour::m_fn_crGetBoundingBox() { CRect cr; GetWindowRect(cr); GetParent()->ScreenToClient(cr); CPoint cpOffset=((CScrollView *)GetParent())->GetScrollPosition(); cr.OffsetRect(cpOffset); return cr; } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vUpdateButtonWidth() { CString csName; GetWindowText(csName); CClientDC cDc(this); cDc.SelectObject(&m_clFont); CSize clRuleSize=cDc.GetTextExtent(csName); CRect cr; GetWindowRect(cr); GetParent()->ScreenToClient(cr); cr.right=cr.left+clRuleSize.cx+20; MoveWindow(cr); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vUpdateDependencies() { /*A VOIR*/ } /****************************************************************************/ //BEGIN ROMTEAM Cristi Petrescu 98-05- void CPA_EdIR_Behaviour::m_fn_vSetCursorPosByLine(long lLineNumber) { long lIndex = m_clEditCtrl . LineIndex (lLineNumber); m_clEditCtrl.m_fn_vSetCursorPos(lIndex); } //END ROMTEAM Cristi Petrescu 98-05- /****************************************************************************/ //BEGIN ROMTEAM Cristi Petrescu 98-08- void CPA_EdIR_Behaviour::m_fn_vSetCursorPosByIndex(long lIndex) { m_clEditCtrl.m_fn_vSetCursorPos(lIndex); } //END ROMTEAM Cristi Petrescu 98-08- /****************************************************************************/ long CPA_EdIR_Behaviour::m_fn_lGetLineNumberInPixel(long lIndex) { return m_clEditCtrl.m_fn_lGetLineNumberInPixel(lIndex); } /****************************************************************************/ long CPA_EdIR_Behaviour::m_fn_lGetStartLineIndex(long lIndex) { return m_clEditCtrl.LineIndex(m_clEditCtrl.LineFromChar(lIndex)); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vDisplayError(long lIndexError) { //ANNECY CB CString csRules=m_clEditCtrl.m_fn_csGetText(); int len = csRules.GetLength(); if((lIndexError < len) && (isspace(csRules.GetAt(lIndexError)))) while((lIndexError < len) && isspace(csRules.GetAt(lIndexError))) lIndexError++; m_lErrorIndex = lIndexError; //END ANNECY //Shows actor editor CPA_DLLBase *pclActorDLL=(CPA_DLLBase*)(g_pclAIInterface->GetMainWorld()->GetObjectDLLWithName(C_szDLLActorName)); g_pclAIInterface->GetMainWorld()->fn_bActivateEditor(pclActorDLL,NULL); //Gets current state CPA_EdIR_Frame *pclIRMainFrame=g_pclAIInterface->m_pclIRMainFrame; tdeEditState tdeOldState=pclIRMainFrame->m_fn_pclGetButtonView()->m_fn_tdeGetEditState(); //Shows current actor CPA_Actor *pclSelectedActor=(CPA_Actor *)pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_GetSelectedActor,0); CPA_Actor *pclSelectedModel=g_pclCurrentModel; if(pclSelectedActor) { if(pclSelectedActor->m_fn_bIsAnInstance()) pclSelectedModel=pclSelectedActor->m_fn_pclGetModel(); else pclSelectedModel=pclSelectedActor; } if((pclSelectedActor == NULL)||(pclSelectedModel!=g_pclCurrentModel)) pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_DisplayActor,(long)g_pclCurrentModel); else pclActorDLL->OnQueryAction(g_pclAIInterface,C_uiActor_DisplayActor,(long)pclSelectedActor); //Sets current state pclIRMainFrame->m_fn_pclGetButtonView()->m_fn_vSetEditState(tdeOldState); //Shows error ((CPA_EdIR_DiagView *)GetParent())->m_fn_vOldActiveBehaviourHasChanged(this); //Stefan Dumitrean 9-06-98 // m_clEditCtrl.m_fn_vSetCursorPos(lIndexError); m_clEditCtrl.SetSel( lIndexError, lIndexError + g_clLex.yyleng ); //End Stefan Dumitrean 9-06-98 m_clEditCtrl.SetFocus(); //Dispatch msgs MSG msg; while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) DispatchMessage(&msg); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : CPA_EdIR_Behaviour::m_fn_csBuildMacroDefinition // Date : 98.03 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// /* CString CPA_EdIR_Behaviour::m_fn_csBuildMacroDefinition (void) { // remove the macro from the global macro list POSITION pos = g_clMacroList . GetHeadPosition(); POSITION oldpos = pos; while (pos != NULL) { CPA_EdIR_Macro *pclMacro = g_clMacroList . GetNext(pos); CString csMacroName = m_fn_csGetName (); csMacroName . MakeLower (); if (csMacroName == pclMacro -> m_fn_csGetMacroName ()) { g_clMacroList . RemoveAt (oldpos); break; } oldpos = pos; } // build the text for a macro, // old format // this is useless, the macro parsing just gets the text. But macro with parameters to come... return "MACRO " + m_fn_csGetName () + " : " + m_clEditCtrl.m_fn_csGetText(); } */ ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : CPA_EdIR_Behaviour::m_fn_vHideNonExecutedLines // Date : 98.05 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void CPA_EdIR_Behaviour::m_fn_vHideNonExecutedLines (void) { m_clEditCtrl . m_fn_vHideNonExecutedLines (& m_pclMainBehaviour -> m_clDebugInfoList); // and recolor the text... m_clEditCtrl . m_fn_vColorText (0, m_clEditCtrl . GetTextLength ()); } /****************************************************************************/ BOOL CPA_EdIR_Behaviour::m_fn_bCheckIA(tdeTypeText eTypeText) { BOOL bNoError = TRUE; long lIndexError; CString csAddText = ""; CString csRules=m_clEditCtrl.m_fn_csGetText(); //ANNECY CB if(m_lErrorIndex > 0) m_pclIAViewRules->InvalidateRect(NULL); m_lErrorIndex = -1; //END ANNECY if(m_bDeclaration && (m_fn_csGetName()==g_c_csDsgVarName)) eTypeText=DsgVarText; if(m_bDeclaration && (m_fn_csGetName()==g_c_csMacroName)) eTypeText=MacroText; if (eTypeText == Macro_2_Text) { // do this only if no Macro declaration already inside // TOTAL HACKING at this point! CString csCleanRules = fn_csGetCodeWithoutComments (csRules); LPCSTR pszCleanRules = (LPCSTR) csCleanRules; LPCSTR pszLowerRules = strlwr((LPSTR)pszCleanRules); LPCSTR pszIndex = pszCleanRules; m_bOldMacro = FALSE; while (pszIndex) { pszIndex = strstr (pszLowerRules, "macro"); if (pszIndex) { BOOL bPreviousSpace; if (pszIndex - 1 < pszLowerRules) bPreviousSpace = TRUE; else bPreviousSpace = isspace (pszIndex [- 1]); BOOL bNextSpace; if (pszIndex [5] != 0) bNextSpace = isspace (pszIndex [5]); else bNextSpace = TRUE; if (bPreviousSpace && bNextSpace) { m_bOldMacro = TRUE; break; } pszIndex += 5; } } if (! m_bOldMacro) { csAddText = "Macro " + m_fn_csGetName () + ":\n"; csRules = csAddText + csRules; } // Add data directly to the global macro table // this will GREATLY help the debugger // some other time //CPA_EdIR_Macro *pclMacro; //pclMacro = new CPA_EdIR_Macro (m_fn_csGetName (), csRules); //g_clMacroList.AddTail(pclMacro); //eTypeText=MacroText; } //else //{ //ANNECY CB //BEGIN ROMTEAM Cristi Petrescu 98-05- CString csBehaviourName; switch (eTypeText) { case IntelligenceText: csBehaviourName = "I:" + m_fn_csGetName (); break; case ReflexText: csBehaviourName = "R:" + m_fn_csGetName (); break; case SubrText: csBehaviourName = "S:" + m_fn_csGetName (); break; default: csBehaviourName = ""; break; } bNoError=fn_bCheckIA(m_pclMainBehaviour,eTypeText,csRules,lIndexError, csBehaviourName); //END ROMTEAM Cristi Petrescu 98-05- // bNoError=fn_bCheckIA(eTypeText,csRules,lIndexError); //END //} if(!bNoError) { if (eTypeText == Macro_2_Text && ! m_bOldMacro) { lIndexError -= csAddText . GetLength (); if (lIndexError<0) lIndexError = 0; } m_fn_vDisplayError(lIndexError); } else { m_bHasBeenModified = FALSE; m_clEditCtrl.m_fn_vSetModified(FALSE); } return bNoError; } /****************************************************************************/ BOOL CPA_EdIR_Behaviour::m_fn_bProcessIA ( BOOL bProcessAll,BOOL bCreateControl, AI_tdstMind *pstMind,tdstComport *pstComport,tdstTreeInterpret *pstRule, tdeTypeText eTypeText,CPA_EdIR_DebugInfoList *pclDebugInfoList ) { //ANNECY CB if(m_lErrorIndex > 0) m_pclIAViewRules->InvalidateRect(NULL); m_lErrorIndex = -1; //END ANNECY //Dispatch msgs for stop button MSG msg; while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) DispatchMessage(&msg); CPA_EdIR_Frame *pclIRMainFrame=g_pclAIInterface->m_pclIRMainFrame; if(!pclIRMainFrame->m_fn_pclGetButtonView()->m_fn_bMustStopProcess()) { long lIndexError; BOOL bNoError; CString csRules=m_clEditCtrl.m_fn_csGetText(); if(m_bDeclaration && (m_fn_csGetName()==g_c_csDsgVarName)) eTypeText=DsgVarText; if(m_bDeclaration && (m_fn_csGetName()==g_c_csMacroName)) //ANNECY CB // eTypeText=MacroText; return TRUE; //END //BEGIN ROMTEAM Cristi Petrescu 98-04- // as you wish... if (eTypeText == Macro_2_Text) return TRUE; //END ROMTEAM Cristi Petrescu 98-04- //BEGIN ROMTEAM Cristi Petrescu 98-05- CString csBehaviourName; switch (eTypeText) { case IntelligenceText: csBehaviourName = "I:" + m_fn_csGetName (); break; case ReflexText: csBehaviourName = "R:" + m_fn_csGetName (); break; case SubrText: csBehaviourName = "S:" + m_fn_csGetName (); break; case CRRGeneration: csBehaviourName = m_fn_csGetName (); break; default: csBehaviourName = ""; break; } bNoError = fn_bProcessIA(bProcessAll,m_pclMainBehaviour,bCreateControl,pstMind,pstComport,pstRule,eTypeText,csRules,lIndexError,pclDebugInfoList,csBehaviourName); //END ROMTEAM Cristi Petrescu 98-05- if(!bNoError) m_fn_vDisplayError(lIndexError); else { if(eTypeText != CRRGeneration) { m_bHasBeenModified = FALSE; m_clEditCtrl.m_fn_vSetModified(FALSE); //BEGIN ROMTEAM Cristi Petrescu 98-05- // and set the line info in the debug! POSITION pos = pclDebugInfoList -> GetHeadPosition (); CPA_EdIR_DebugInfo *pclDebugInfo; while (pos) { pclDebugInfo = pclDebugInfoList -> GetNext (pos); long lIndex = pclDebugInfo -> m_fn_lGetIndex (); long lLineNumber = m_clEditCtrl . LineFromChar (lIndex); pclDebugInfo -> m_fn_vSetLineNumber (lLineNumber); } } //END ROMTEAM Cristi Petrescu 98-05- } return bNoError; } else return FALSE; } /****************************************************************************/ BOOL CPA_EdIR_Behaviour::m_fn_bSaveIA(SCR_tdst_File_Description *p_tdstFile,AI_tdstMind *pstMind,tdeTypeText eTypeText, CString csInfo) { long lIndexError; BOOL bNoError; if(m_lErrorIndex > 0) m_pclIAViewRules->InvalidateRect(NULL); m_lErrorIndex = -1; CString csRules=m_clEditCtrl.m_fn_csGetText(); if(eTypeText != CRRGeneration) { if (eTypeText == SubrText) { CString csName = m_fn_csGetName (); csInfo = csName + " " + csInfo; } if(m_bDeclaration && (m_fn_csGetName()==g_c_csDsgVarName)) eTypeText=DsgVarText; if(m_bDeclaration && (m_fn_csGetName()==g_c_csMacroName)) eTypeText=MacroText; } CString csBehaviourName; switch (eTypeText) { case IntelligenceText: csBehaviourName = "I:" + m_fn_csGetName (); break; case ReflexText: csBehaviourName = "R:" + m_fn_csGetName (); break; case SubrText: csBehaviourName = "S:" + m_fn_csGetName (); break; default: csBehaviourName = ""; break; } bNoError=fn_bSaveIA(p_tdstFile,pstMind,eTypeText,csRules,lIndexError, csInfo, csBehaviourName); if(!bNoError) m_fn_vDisplayError(lIndexError); else if(eTypeText != CRRGeneration) { m_bHasBeenModified = FALSE; m_clEditCtrl.m_fn_vSetModified(FALSE); } return bNoError; } /****************************************************************************/ BOOL CPA_EdIR_Behaviour::m_fn_bHasBeenModified() { return (m_bHasBeenModified||m_clEditCtrl.m_fn_bHasBeenModified()); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vSetModified(BOOL bIsModified) { m_bHasBeenModified=bIsModified; m_clEditCtrl.m_fn_vSetModified(bIsModified); } /****************************************************************************/ BOOL CPA_EdIR_Behaviour::m_fn_bIntermediateCodeListIsGood() { return m_bIntermediateCodeListIsGood && (m_fn_bHasBeenModified()==FALSE); } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vSetIntermediateCodeList(BOOL bIntermediateCodeListIsGood) { m_bIntermediateCodeListIsGood=bIntermediateCodeListIsGood; } /****************************************************************************/ void CPA_EdIR_Behaviour::m_fn_vRegisterInTUT() { ////////////// ////////////// //Registers for TUT Module TUT_M_vGetTutDll(); CPA_EdIR_MainBehaviour *pclMainBehaviour=m_fn_pclGetMainBehaviour(); CString csName=pclMainBehaviour->GetOwner()->GetName()+"_"+pclMainBehaviour->GetName(); TUT_M_vRegisterControl(m_clEditCtrl.m_hWnd,"EdIR_EditCtrl_"+csName,TUT_e_TextEdit); //End of Register for TUT Module } #endif //D_ED_IR_ACTIVE