// /*============================================================================= * * Filename: MMatObj.cpp * Version: 1.0 * Date: 06/11/96 * Author: B.G. * * Description: implementation of editor material class * *===========================================================================*/ #include "stdafx.h" #include "Acp_base.h" #include "itf.h" #include "gmt.h" #include "IncMEC.h" #include "gli.h" #include "x:\cpa\main\inc\_editid.h" #include "inctex.h" #include "_interf.hpp" #include "MMatObj.hpp" extern Material_Interface *gs_p_oMaterialInterface; //================================================================================= //================================================================================= //================================================================================= //constructor. the object is name with the following rules //1. it is not a clone but will directly handle the engine material // -> will take the name from the section for the engine material //2. it is a clone, and a name is specified // -> an underscore is added to the original's name, // because someday the base constructor will add a number there //3. it is a clone, and no name is specified // -> the default name is given by the base constructor //================================================================================= tdoEditorMechanicsMaterial::tdoEditorMechanicsMaterial( CPA_FileObject *_p_oOwnerFile, CString _csId, BOOL _bSectionAlreadyExists, DNM_tdxHandleToMecMatCharacteristics _hTemplateMechanicsMaterial ) : CPA_SaveObject( gs_p_oMaterialInterface, //editor C_szMechanicsMaterialTypeName, //type E_ss_Responsible, //responsibility _p_oOwnerFile, //owner (the file containing the section) FALSE, //available (char*)LPCTSTR(_p_oOwnerFile->GetCompletionPath(gs_p_oMaterialInterface, C_szFileReferencedNameKey)), //data path to complete the referenced section name m_vCallBackSaveMMT//callback ) { //tell the file object that an object exists for its section g_oCoherenceManager.m_fn_vAddALink(_p_oOwnerFile, this); //the editor object directly handles the engine object m_hMechanicsMaterial = _hTemplateMechanicsMaterial; SetAvailable(DNM_fn_bIsMatCharacteristicsValid(_hTemplateMechanicsMaterial)); // construct section name (hack: szSectionName is here as an anti-bug for ...Split... char szSectionName[SCR_CV_ui_Cfg_MaxLenName]; SCR_fn_v_RdL0_ComputeSectionName( szSectionName, (char*)LPCTSTR(_p_oOwnerFile->GetReferencedName(gs_p_oMaterialInterface, C_szFileReferencedNameKey)), C_SectionMecMatCharacteristics, (char*)LPCTSTR(_csId) ); // section object SetSectionData(this); SetReferencedSectionName(szSectionName); // name if ( fn_eRename(_csId) != E_mc_None ) SetDefaultValidName() ; fn_vUpdateSectionName() ; if ( _bSectionAlreadyExists ) fn_vSectionSaved(); //the section is saved, and has no pending notification else fn_vSectionDeleted(); //the section does not exist, and has no pending nofitication if ( fn_bCanBeNotified() && !fn_bSectionExists() ) fn_vNotifySave() ; m_bIsHighlighted = FALSE; m_stHighlightColor.xR = (GEO_tdxColorValue) 0.7; m_stHighlightColor.xG = (GEO_tdxColorValue) 0.3; m_stHighlightColor.xB = (GEO_tdxColorValue) 0.0; } //================================================================================= //================================================================================= tdoEditorMechanicsMaterial::~tdoEditorMechanicsMaterial() { //remove myself totally from the coherence manager database if ( !fn_bSectionExists() ) g_oCoherenceManager.m_fn_vRemoveAllLinks(this, C_cLinkedAsChild); } //================================================================================= //================================================================================= void tdoEditorMechanicsMaterial::m_vAssociateEngineMaterial( DNM_tdxHandleToMecMatCharacteristics _hMechanicsMaterial, BOOL /*_bSectionAlreadyExists*/ ) { //make the list update the data sort order fn_vUpdateData(_hMechanicsMaterial); //now we can set the value that will be returned by GetData() m_hMechanicsMaterial = _hMechanicsMaterial; SetAvailable(DNM_fn_bIsMatCharacteristicsValid(_hMechanicsMaterial)); } //================================================================================ //================================================================================ BOOL tdoEditorMechanicsMaterial::m_bIsReferenced() { return g_oCoherenceManager.m_fn_iGetFatherCount(this) > 1; } //================================================================================= //================================================================================= void tdoEditorMechanicsMaterial::m_vLoadAssociatedEngineMaterial() { if ( !fn_bIsAvailable() ) { //if the section name is not in the linktable, analyse the section SCR_tdst_Cxt_Values *p_stAnalyzeResult = SCR_fnp_st_RdL0_AnalyseSection( (char *) LPCTSTR(GetReferencedSectionName()), SCR_CDF_uw_Anl_Normal ); DNM_tdxHandleToMecMatCharacteristics hMechanicsMaterial = (DNM_tdxHandleToMecMatCharacteristics) p_stAnalyzeResult->a_ulValues[0]; //there must not already exist an editor material for the loaded game material! ASSERT(!gs_p_oMaterialInterface->m_p_oGetEditorObjectForEngine(hMechanicsMaterial)); //create the association m_vAssociateEngineMaterial(hMechanicsMaterial, TRUE); } } /*================================================================================= //save a section of the form: {MechanicalMaterial: Adhesion(0.0603564) Absorption(0.0603564) Friction(0.0603564) Slide(0.0603564) Progression(0.0603564) PenetrationSpeed(0.0603564) PenetrationMax(0.0603564) } //=================================================================================*/ void tdoEditorMechanicsMaterial::m_vCallBackSaveMMT( SCR_tdst_File_Description *_p_stFile, char *_p_szSectionName, void *_p_vData, SCR_tde_Ntfy_Action _eAction ) { tdoEditorMechanicsMaterial *p_oEditorMaterial = (tdoEditorMechanicsMaterial *) _p_vData; if ( _eAction == SCR_EA_Ntfy_DeleteSection ) //now the section exists, if this was not the case p_oEditorMaterial->fn_vSectionDeleted(); //the section does not exist, and has no pending nofitication if ( _eAction != SCR_EA_Ntfy_AddSection && _eAction != SCR_EA_Ntfy_RebuildSection ) return; if ( _eAction == SCR_EA_Ntfy_AddSection ) { // go to end of file (we need all file directive to load this section) SCR_fn_v_SvL1_ToEndSection(_p_stFile); SCR_M_SvL0_SaveBlankLine (_p_stFile); } char szSectionName[SCR_CV_ui_Cfg_MaxLenName],szAction[SCR_CV_ui_Cfg_MaxLenName],szId[SCR_CV_ui_Cfg_MaxLenName]; // construct section name (hack: szSectionName is here as an anti-bug for ...Split... SCR_fn_v_RdL0_SplitSectionName(_p_szSectionName, szSectionName, szAction, szId); SCR_fn_v_RdL0_ComputeSectionName(szSectionName, NULL, szAction, szId); // save begin section for the game material (action == MechanicalMaterial) SCR_M_SvL0_SaveBeginSection(_p_stFile, szSectionName, SCR_CC_C_Cfg_EOL); //get the handles we need DNM_tdxHandleToMecMatCharacteristics hMaterialMechanics = p_oEditorMaterial->m_hGetEngineMaterial(); //get the parameters we want to save MTH_tdxReal xCoeff; xCoeff = DNM_fn_xMatCharacteristicsGetSlide (hMaterialMechanics); SCR_M_SvL0_SaveEntry(_p_stFile, C_EntrySlide, SCR_CC_C_Cfg_NoChar); SCR_fn_v_SvL0_SaveParameters_MP(_p_stFile, SCR_EF_SvL0_ArrayFloat, 2, 1, &xCoeff); xCoeff = DNM_fn_xMatCharacteristicsGetRebound (hMaterialMechanics); SCR_M_SvL0_SaveEntry(_p_stFile, C_EntryRebound, SCR_CC_C_Cfg_NoChar); SCR_fn_v_SvL0_SaveParameters_MP(_p_stFile, SCR_EF_SvL0_ArrayFloat, 2, 1, &xCoeff); // End Section SCR_M_SvL0_SaveEndSection(_p_stFile, SCR_CC_C_Cfg_EOL); //now the section exists, if this was not the case p_oEditorMaterial->fn_vSectionSaved(); // the section is saved and has no pending notification } //================================================================================= //================================================================================= BOOL tdoEditorMechanicsMaterial::m_bGetHighlightColor(GEO_tdstColor *_p_stColor /*= NULL*/) { if ( m_bIsHighlighted && _p_stColor ) *_p_stColor = m_stHighlightColor; return m_bIsHighlighted; } //================================================================================= //================================================================================= void tdoEditorMechanicsMaterial::m_vSetHighlightColor(GEO_tdstColor _stColor) { m_stHighlightColor = _stColor; } //================================================================================= //================================================================================= //================================================================================= // static functions for the class //================================================================================= //================================================================================= //================================================================================= SCR_tdst_Link_Table *tdoEditorMechanicsMaterial::m_p_stGetAssociatedLinkTable() { return DNM_fn_p_stGetLinkTableOfMecMatCharacteristics(); } BOOL tdoEditorMechanicsMaterial::m_bIsEngineMaterialValid(DNM_tdxHandleToMecMatCharacteristics _hMechanicsMaterial) { return DNM_fn_bIsMatCharacteristicsValid(_hMechanicsMaterial); } /*CString tdoEditorMechanicsMaterial::m_csGetBaseDataPath() { return fn_szGetMechanicsMaterialDataPath(); }*/ void tdoEditorMechanicsMaterial::m_vInvalidateEngineMaterial(DNM_tdxHandleToMecMatCharacteristics &r_hMechanicsMaterial) { DNM_fn_vInvalidateMatCharacteristics(&r_hMechanicsMaterial); } CString tdoEditorMechanicsMaterial::m_csGetMaterialType() { return C_szMechanicsMaterialTypeName; } CString tdoEditorMechanicsMaterial::m_csGetScriptExtension() { return ".mmt"; }