// Implementation for the class CMyDocument ///////////////////////////////////////////// #include "StdAfx.h" #include "SCR.h" #include "EMECDoc.hpp" #include "EMECVwMn.hpp" #include "EMECVwMS.hpp" #include "EMECStrg.hpp" #include "EMECDgNC.hpp" #include "_Minterf.hpp" #include "x:\cpa\main\inc\_EditID.h" //External modules #include "ErO.h" #include "Dpt.h" //End of External modules long g_lCurrentId = 2000; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //**************************************************************************** CPA_Meca_MyDocument::CPA_Meca_MyDocument() { // AfxEnableMemoryTracking(TRUE); //Initializes editor's state m_pclCurrentCardType = NULL; m_pclCurrentCard = NULL; m_pclControlView = NULL; m_pclMiniStrucView = NULL; m_pclDialogList = NULL; //Editor's Setup var. Init. m_ulListViewHeight = 170; m_ulControlViewHeight = 250; m_ulEditorWidth = 260; //Other init. m_fn_vInitialize(); } //**************************************************************************** CPA_Meca_MyDocument::~CPA_Meca_MyDocument() { m_fn_bWriteIniFile(); } //**************************************************************************** //Extra init. void CPA_Meca_MyDocument::m_fn_vInitialize() { //Constructs the list of Enum desciptors m_fn_vConstructListOfEnumDescriptors(); //Fills the mini-structure list (controls) m_fn_vFillCardsTypeList(); //Init. the INI file name m_csIniFileName = M_GetMainApp()->m_csEditorDataPath + "Tools\\Meca\\EdMeca.ini"; //Reads INI file m_fn_bReadIniFile(); m_pub_fn_bLoadPreferences(); //PROVISOIRE... m_csHelpFileNameAndPath = M_GetMainApp()->m_csEditorDataPath + "Tools\\Meca\\Meca.hlp >Normale"; } ///////////////////// // Editor's aspect // ///////////////////// //*************************************************************************** // ... void CPA_Meca_MyDocument::m_fn_vEditCard(CPA_Meca_Card *pclNewCard) { m_pclCurrentCard = pclNewCard; if ( m_pclMiniStrucView != NULL ) { if ( pclNewCard != NULL ) { if ( (pclNewCard->m_fn_pclGetCardType()->m_fn_bControlsAreHidden()) || (m_pclCurrentCardType == NULL) ) //Forces "Repaint" m_fn_vDisplayCardType(pclNewCard->m_fn_pclGetCardType(), TRUE); m_fn_vSetPointersForSelectedCard(); m_pclMiniStrucView->m_fn_vEditCard(m_pclCurrentCard); m_pclControlView->m_fn_vUpdateCardsName(); //Sets new Card as Type Card's current Card pclNewCard->m_fn_pclGetCardType()->m_fn_vSetEditedCard(pclNewCard); } else { if ( !m_pclCurrentCardType->m_fn_bControlsAreHidden() ) m_pclCurrentCardType->m_fn_vHideAllControls(); //Sets new Card as Type Card's current Card m_pclCurrentCardType->m_fn_vSetEditedCard(pclNewCard); } } } //*************************************************************************** // ... void CPA_Meca_MyDocument::m_fn_vDisplayCardType(CPA_Meca_CardType *pclNewCardType, BOOL bForcesRepaint /*= FALSE*/) { if ( (pclNewCardType != m_pclCurrentCardType) || (bForcesRepaint) ) { m_pclCurrentCardType = pclNewCardType; if ( m_pclMiniStrucView ) m_pclMiniStrucView->m_fn_vDisplayCardType(m_pclCurrentCardType, TRUE); if ( m_pclCurrentCardType != NULL ) { if ( m_pclCurrentCardType->m_fn_ulGetCardsNumber() == 0 ) { //PROVISOIRE... m_pclCurrentCardType->m_fn_vHideAllControls(); //Refreshes buttons ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_DELETE))->EnableWindow( FALSE ); ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_RENAME))->EnableWindow( FALSE ); ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_COPY))->EnableWindow( FALSE ); m_pclCurrentCardType->m_fn_vSetEditedCard(NULL); } else { //Refreshes buttons if ( m_pclCurrentCardType->m_fn_pclGetEditedCard() != NULL ) { ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_DELETE))->EnableWindow( TRUE ); ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_RENAME))->EnableWindow( TRUE ); ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_COPY))->EnableWindow( TRUE ); } else { ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_DELETE))->EnableWindow( FALSE ); ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_RENAME))->EnableWindow( FALSE ); ((CButton *)m_pclControlView->GetDlgItem(IDC_BUTTON_COPY))->EnableWindow( FALSE ); } } } //Selects in the List Box CListBox *pclTypeLB = (CListBox *)m_pclControlView->GetDlgItem(IDC_LIST_CARD_TYPES); pclTypeLB->SelectString(-1, m_pclCurrentCardType->m_fn_csGetCardTypeName()); } } //*************************************************************************** // ... void CPA_Meca_MyDocument::m_fn_vReInitDisplay() { CListBox *pclTypeLB = (CListBox *)m_pclControlView->GetDlgItem(IDC_LIST_CARD_TYPES); pclTypeLB->SetCurSel(0); m_pclControlView->OnSelchangeComboCardTypes(); //Updates Dialog List m_pclDialogList->fn_vReinitDialog(); } //********************************************************************************************** CPA_Meca_Card *CPA_Meca_MyDocument::m_pub_fn_vCreateCopyOfCard(CPA_Meca_Card *_pclSourceCard) { ERROR_ASSERT( _pclSourceCard != NULL ); CPA_Meca_Card *pclNewCard = NULL; //Creates Card ////////////////// //Gets user wanted name CString csCopyName = _pclSourceCard->GetName() + "_Copy"; CPA_Meca_NewCardDialog dial(csCopyName, m_pclControlView); if ( dial.DoModal() == IDOK ) { csCopyName = dial.m_csName; CPA_Meca_CardType *pclCardType = _pclSourceCard->m_fn_pclGetCardType(); pclNewCard = pclCardType->m_fn_pclGetCardsList()->m_fn_pclAddElement( csCopyName, _pclSourceCard->m_fn_pclGetCardType(), NULL, _pclSourceCard->m_fn_pclGetCardType()->m_fn_csGetFileName(), _pclSourceCard->m_fn_pclGetCardType()->m_fn_csGetActionName()); //Copies Data from source Card POSITION SourcePos = _pclSourceCard->m_clDataList.GetHeadPosition(); POSITION NewCardPos = pclNewCard->m_clDataList.GetHeadPosition(); while ( SourcePos != NULL ) { ERROR_ASSERT( NewCardPos != NULL ); pclNewCard->m_clDataList.GetNext(NewCardPos)->m_fn_vUpdateData(_pclSourceCard->m_clDataList.GetNext(SourcePos)); } ERROR_ASSERT( NewCardPos == NULL ); } return pclNewCard; } /////////////////////// // Private functions // /////////////////////// //********************************************************************************************** //Sets the pointer on a Data (the one of the Card) in each control of Card Type void CPA_Meca_MyDocument::m_fn_vSetPointersForSelectedCard() { m_fn_vSetPointersForCard(m_pclCurrentCard); } //********************************************************************************************** //Sets the pointer on a Data (the one of the Card) in each control of Card Type void CPA_Meca_MyDocument::m_fn_vSetPointersForCard(CPA_Meca_Card *pclCard) { if ( pclCard != NULL ) { ERROR_PREPARE_M(g_c_csMecaModuleNameForErrors, "Linking a Card to a Card Type (i.e. data to controls)", "CPA_Meca_MyDocument::m_fn_vSetPointersForCard(...)", E_ERROR_GRAVITY_FATAL, "The given Card Type is invalid"); ERROR_ASSERT( m_pclCurrentCardType != NULL ); ERROR_PREPARE_M(g_c_csMecaModuleNameForErrors, "Linking a Card to a Card Type (i.e. data to controls)", "CPA_Meca_MyDocument::m_fn_vSetPointersForCard(...)", E_ERROR_GRAVITY_FATAL, "The type of the Card differs from the one of the Type Card..."); ERROR_ASSERT( m_pclCurrentCardType == pclCard->m_fn_pclGetCardType() ); m_pclCurrentCardType->m_clControlList.m_pub_fn_vUpdateControlsWithListOfData(&pclCard->m_clDataList); } } //********************************************************************************************** //Removes a Card from a Card Type's list void CPA_Meca_MyDocument::m_fn_vRemoveCard(CPA_Meca_Card *pclCard) { ERROR_PREPARE_M(g_c_csMecaModuleNameForErrors, "Trying to delete a Mechanical Card", "CPA_Meca_MyDocument::m_fn_vRemoveCard(...)", E_ERROR_GRAVITY_FATAL, "The Card to be deleted is invalid"); ERROR_ASSERT( pclCard != NULL ); CPA_Meca_CardType *pclCardType = pclCard->m_fn_pclGetCardType(); ERROR_PREPARE_M(g_c_csMecaModuleNameForErrors, "Trying to delete a Mechanical Card", "CPA_Meca_MyDocument::m_fn_vRemoveCard(...)", E_ERROR_GRAVITY_FATAL, "The type of the Card to be deleted is invalid"); ERROR_ASSERT( pclCardType != NULL ); POSITION pos = pclCardType->m_fn_pclGetCardsList()->Find(pclCard); ERROR_PREPARE_M(g_c_csMecaModuleNameForErrors, "Trying to delete a Mechanical Card", "CPA_Meca_MyDocument::m_fn_vRemoveCard(...)", E_ERROR_GRAVITY_FATAL, "The Card to be deleted has not been found in the Editor list"); ERROR_ASSERT( pos != NULL ); //Removes from list pclCardType->m_fn_pclGetCardsList()->RemoveAt(pos); //Notifies pclCard->fn_vNotifyUnSave(); //deletes delete pclCard; //Selects another Card m_fn_vEditCard(pclCardType->m_fn_pclGetCardsList()->m_pub_fn_pclGetFirstAvailableCard()); } //********************************************************************************************** void CPA_Meca_MyDocument::m_fn_vCheckSpacesInString(CString &r_csStringToCheck) { CString csSpace(" "); for (int c_lI = 0; c_lI < r_csStringToCheck.GetLength(); c_lI ++) if ( r_csStringToCheck[c_lI] == csSpace ) r_csStringToCheck.SetAt(c_lI, '_'); } //********************************************************************************************** void CPA_Meca_MyDocument::m_fn_vSearchForLoadedCards() { //Uses LinkTables SCR_tdst_Link_Table *p_stLinkTable = DNM_fn_p_stGetLinkTableOfIdCard(); unsigned int uiPos = 0; SCR_tdst_Link_Value *p_stValue; CPA_Meca_Card *pclAddedCard = NULL; CPA_Meca_CardType *pclConcernedCardType = NULL; /* Get first element of array */ SCR_M_DyAr_GetNextElement(SCR_tdst_Link_Value, uiPos, p_stValue, SCR_M_st_Link_GetDynamicArray(p_stLinkTable) ) while( p_stValue != NULL ) /* p_sValue is NULL at the end of the array */ { /* Test current retrieved value */ if( SCR_M_e_Link_GetState(p_stValue) == SCR_ELS_Link_Initialized ) { DNM_tdxHandleToMecIdentityCard h_IdCard = (DNM_tdxHandleToMecIdentityCard)SCR_M_ul_Link_GetValue(p_stValue); //Gets the Name for the Card CString csCardName(SCR_M_p_sz_Link_GetKey(p_stValue)); char a_256cFileName[256]; char a_256cActionName[256]; char a_256cName[256]; SCR_fn_v_RdL0_SplitSectionName((char *)LPCTSTR(csCardName), a_256cFileName, a_256cActionName, a_256cName); csCardName = a_256cName; //Gets the Motor Type for the Card DNM_tdeMechanicsID tdeMotorType; memcpy(&tdeMotorType, h_IdCard, sizeof(DNM_tdeMechanicsID)); //Adds to Card Type's list od Cards pclConcernedCardType = m_clCardTypeList.m_fn_pclGetTypeCardFromID(tdeMotorType); pclAddedCard = pclConcernedCardType->m_fn_pclGetCardsList()->m_fn_pclAddElement(csCardName, pclConcernedCardType, h_IdCard, a_256cFileName, a_256cActionName); //Adds to the Main list m_clListOfCards.fn_bAddObject(pclAddedCard); pclAddedCard->SetExistingSection(TRUE); pclConcernedCardType->m_bAtLeastOneCardOfTheCardTypeHasBeenLoaded = TRUE; } /* Get next element */ uiPos++; SCR_M_DyAr_GetNextElement(SCR_tdst_Link_Value, uiPos, p_stValue, SCR_M_st_Link_GetDynamicArray(p_stLinkTable) ) } } //********************************************************************************************** void CPA_Meca_MyDocument::m_fn_vLoadUnloadedCards() { CPA_Meca_CardType *pclCurrentTypeCard; POSITION pos= m_clCardTypeList.GetHeadPosition(); while ( pos != NULL ) { pclCurrentTypeCard = m_clCardTypeList.GetNext(pos); CString csCompleteFileName = fn_szGetMechanicsDataPath(); csCompleteFileName += CString("\\") + pclCurrentTypeCard->m_fn_csGetFileName(); CFile cfPrivateFile; if ( cfPrivateFile.Open(csCompleteFileName, CFile::modeRead ) ) { cfPrivateFile.Close(); char *szFileName = (char *)LPCTSTR(pclCurrentTypeCard->m_fn_csGetFileName()); //Gets all the sections in the corresponding file SCR_fn_v_RdL0_OpenFile(szFileName); //Gets a pointer on the file SCR_tdst_File_Open *p_tdstFile = SCR_fnp_st_RdL0_GetOpenFile(szFileName); unsigned int uiPos = 0; SCR_tdst_Anl_SectionDes_ *p_stValue; CPA_Meca_Card *pclAddedCard = NULL; BOOL bCardIsNotLoaded; /* Get first element of array */ SCR_M_DyAr_GetNextElement(SCR_tdst_Anl_SectionDes_, uiPos, p_stValue, p_tdstFile->stSectionsDes ) while( p_stValue != NULL ) /* p_sValue is NULL at the end of the array */ { //Gets the Name for the Card CString csCardName(p_stValue->stBuffers.p_szBufferCompleteName); char a_256cFileName[256]; char a_256cActionName[256]; char a_256cName[256]; SCR_fn_v_RdL0_SplitSectionName((char *)LPCTSTR(csCardName), a_256cFileName, a_256cActionName, a_256cName); csCardName = a_256cName; // Tests if Card is already loaded bCardIsNotLoaded = ( g_pclInterface->GetMainWorld()->fn_p_oFindObject(csCardName, C_szMecaCardTypeName) == NULL ); //Creates an unloaded Card if necessary if ( bCardIsNotLoaded ) { //Adds to Card Type's list od Cards pclAddedCard = pclCurrentTypeCard->m_fn_pclGetCardsList()->m_fn_pclAddElement(csCardName, pclCurrentTypeCard, NULL, a_256cFileName, a_256cActionName, TRUE); pclAddedCard->SetAvailable(FALSE); //Adds to the Main list m_clListOfCards.fn_bAddObject(pclAddedCard); pclAddedCard->SetExistingSection(TRUE); } /* Get next element */ uiPos++; SCR_M_DyAr_GetNextElement(SCR_tdst_Anl_SectionDes_, uiPos, p_stValue, p_tdstFile->stSectionsDes ) } } } } //********************************************************************************************** void CPA_Meca_MyDocument::m_fn_vUpdateUnLoadedCards() { //Uses LinkTables SCR_tdst_Link_Table *p_stLinkTable = DNM_fn_p_stGetLinkTableOfIdCard(); unsigned int uiPos = 0; SCR_tdst_Link_Value *p_stValue; CPA_Meca_Card *pclEditorCard = NULL; CPA_Meca_CardType *pclConcernedCardType = NULL; /* Get first element of array */ SCR_M_DyAr_GetNextElement(SCR_tdst_Link_Value, uiPos, p_stValue, SCR_M_st_Link_GetDynamicArray(p_stLinkTable) ) while( p_stValue != NULL ) /* p_sValue is NULL at the end of the array */ { /* Test current retrieved value */ if( SCR_M_e_Link_GetState(p_stValue) == SCR_ELS_Link_Initialized ) { DNM_tdxHandleToMecIdentityCard h_IdCard = (DNM_tdxHandleToMecIdentityCard)SCR_M_ul_Link_GetValue(p_stValue); //Gets the Name for the Card CString csCardName(SCR_M_p_sz_Link_GetKey(p_stValue)); char a_256cFileName[256]; char a_256cActionName[256]; char a_256cName[256]; SCR_fn_v_RdL0_SplitSectionName((char *)LPCTSTR(csCardName), a_256cFileName, a_256cActionName, a_256cName); csCardName = a_256cName; //Gets the Motor Type for the Card DNM_tdeMechanicsID tdeMotorType; memcpy(&tdeMotorType, h_IdCard, sizeof(DNM_tdeMechanicsID)); //Adds to Card Type's list of Cards pclConcernedCardType = m_clCardTypeList.m_fn_pclGetTypeCardFromID(tdeMotorType); //Searches for object with same name pclEditorCard = (CPA_Meca_Card *)g_pclInterface->GetBaseObject(csCardName, C_szMecaCardTypeName); ERROR_PREPARE_M(g_c_csMecaModuleNameForErrors, "Updating unloaded Mechanical Cards (because a Family has been loaded)", "CPA_Meca_MyDocument::m_fn_vUpdateUnLoadedCards()", E_ERROR_GRAVITY_WARNING, "No Editor Card found for one of the Motor Cards"); ERROR_ASSERT( pclEditorCard != NULL ); if( (pclEditorCard != NULL) && (!pclEditorCard->fn_bIsAvailable()) ) { // Updates engine poniter pclEditorCard->m_fn_vSetBaseAddress(h_IdCard); pclEditorCard->SetAvailable(TRUE); pclConcernedCardType->m_bAtLeastOneCardOfTheCardTypeHasBeenLoaded = TRUE; pclConcernedCardType->m_p_fn_vFill(pclEditorCard); DNM_tdstMecBaseIdCard *pMecCard = (DNM_tdstMecBaseIdCard *)pclEditorCard->m_fn_pvGetBaseAddress(); DNM_M_vBaseIdCardSetSlopeLimit ( pMecCard, MTH_M_xRadToDeg ( MTH_M_xATan (DNM_M_xBaseIdCardGetSlopeLimit(pMecCard))) ); } } /* Get next element */ uiPos++; SCR_M_DyAr_GetNextElement(SCR_tdst_Link_Value, uiPos, p_stValue, SCR_M_st_Link_GetDynamicArray(p_stLinkTable) ) } }