2026-03-21 12:50:26 -05:00
//+------------------------------------------------------------------+
//| FeaturesEditor.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372 |
//+------------------------------------------------------------------+
# property copyright " Copyright 2025, Niquel Mendoza. "
# property link " https://www.mql5.com/es/users/nique_372 "
# property strict
# ifndef AIDATATASKRUNER_UI_FEATURESEDITOR_FEAUTRESEDITOR_MQH
# define AIDATATASKRUNER_UI_FEATURESEDITOR_FEAUTRESEDITOR_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2026-04-25 21:51:27 -05:00
//--- Editor de codigo
# include <TSN\\EAFModExt\\CodeEditor.mqh>
//--- Compilador de FGBLC
// Importamos feautes primero para que el define padre prevaslesca (osea el AIDATA_LEO_FEATURE_FIRST no sea basic)
2026-07-15 20:05:24 -05:00
# include <TSN\\AiDataGen\\GenericData\\AllFeatures.mqh>
2026-03-21 12:50:26 -05:00
# include <TSN\\AiDataGen\\GenericData\\Complex.mqh>
2026-07-15 20:05:24 -05:00
2026-04-25 21:51:27 -05:00
//--- Defines para GUIS
2026-03-25 21:39:19 -05:00
# include "..\\Defines.mqh"
2026-03-21 12:50:26 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string g_arr_feautres_editor_templates [ 2 ] =
{
2026-07-13 11:53:38 -05:00
" ict_features.yaml " ,
" complex_features.yaml "
2026-03-21 12:50:26 -05:00
} ;
/*
[ CFeaturesCodeEditor ]
// Aqui iria lo de BasicEditor
m_buttom_compile = " Compile "
m_buttom_compile_tooltip = " Click aqui para compilar "
//--- Mensaes de error al compilar
OnCompile_err_select_file = " Fallo al selecionar archivos "
OnCompile_err_compile = " Fallo al compilar el FGBLC, revise los logs "
OnCompile_err_save_file = " Fallo al guardar los archivos "
* /
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CFeaturesCodeEditor : public CBasicCodeEditor
{
private :
CButton m_buttom_compile ;
void OnCompile ( ) ;
//---
int m_common_flag ; // bandera common en caso el base path este en common
//---
2026-07-07 13:38:29 -05:00
TSN : : CAiLeoMulyiFeatureGen m_compiler ;
TSN : : CYamlParser m_yml ;
2026-03-21 12:50:26 -05:00
public :
CFeaturesCodeEditor ( void ) : CBasicCodeEditor ( " CFeaturesCodeEditor " ) { }
~ CFeaturesCodeEditor ( void ) { }
//---
bool OnClickButtom ( const long lparam ) ;
//---
bool CreateExtra ( CWindow & main_window , const bool comon_flag , const CodeEditorColors & clrs ) ;
//---
void OnLenguajeChange ( ) override final ;
} ;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CFeaturesCodeEditor : : OnClickButtom ( const long lparam )
{
if ( lparam = = m_buttom_compile . Id ( ) )
{
OnCompile ( ) ;
return true ;
}
return CBasicCodeEditor : : OnClickButtom ( lparam ) ;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CFeaturesCodeEditor : : CreateExtra ( CWindow & main_window , const bool comon_flag , const CodeEditorColors & clrs )
{
//---
m_common_flag = comon_flag ? FILE_COMMON : 0 ;
//---
int x = m_combox_load_code . XGap ( ) + m_combox_load_code . XSize ( ) + 20 ;
int y = m_buttom_save_code . YGap ( ) ;
//---
const string txt = GUIBASE_COMPONENT_NAME ( m_buttom_compile ) ;
//---
m_buttom_compile . YSize ( clrs . btn_ysize ) ;
m_buttom_compile . Tooltip ( m_language . Tooltip ( txt ) ) ;
ApplyButtonStyle ( m_buttom_compile , clrs ) ;
if ( ! m_padre . CreateButton ( m_buttom_compile , m_language [ txt ] ,
main_window , 0 , m_base_tab , m_base_tab_idx , x , y , 100 ) )
{
GUIBASE_ERROR_CREATION ( m_buttom_compile ) ;
return false ;
}
//---
return true ;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CFeaturesCodeEditor : : OnCompile ( void )
{
//---
2026-03-25 21:39:19 -05:00
string file_name_out = " " ;
if ( m_current_file_name .Length ( ) > 4 ) // minimo .txt
2026-03-21 12:50:26 -05:00
{
2026-03-25 21:39:19 -05:00
file_name_out = m_current_file_name ;
2026-03-21 12:50:26 -05:00
}
2026-03-25 21:39:19 -05:00
else
{
string arr [ ] ;
2026-07-13 11:53:38 -05:00
if ( FileSelectDialog ( m_file_select_dialog_cap , AIDATATASKRUNER_PATH_FEATURES_EDITOR ,
" TXT files (*.txt)|*.txt|FGBLC files (*.fgblc)|*.fgblc|YAML files (*.yaml;*.yml)|*.yaml;*.yml " ,
2026-03-25 21:39:19 -05:00
( ( m_common_flag & FILE_COMMON ) ! = 0 ? FSD_COMMON_FOLDER : 0 ) | FSD_FILE_MUST_EXIST , arr , NULL ) < 1 ) // el archivo debera de exisitr
{
MessageBox ( GUIBASE_MSG ( " err_select_file " ) , GUIBASE_COMMON ( " error " ) , MB_ICONERROR | MB_OK ) ;
return ;
}
file_name_out = arr [ 0 ] ;
}
2026-03-21 12:50:26 -05:00
//--- Check
2026-07-07 13:38:29 -05:00
string csv ;
2026-03-21 12:50:26 -05:00
const bool comon_folder = ( m_common_flag & FILE_COMMON ) ! = 0 ;
2026-07-07 13:38:29 -05:00
const int ret = m_yml . AssingFile ( file_name_out , comon_folder ) ; // Obtenemos ret type
m_yml . CorrectPadding ( ) ; // Corregimos padding
if ( ret = = -1 | | ! m_yml . AutoParseByFileExt ( ret ) // En caso haya fallado la lecutra o el parseo... error
| | ! m_compiler . Compile ( m_yml . GetRoot ( ) , csv ) ) // Tambien en caso no se pudo procesar...
2026-03-21 12:50:26 -05:00
{
2026-03-25 21:39:19 -05:00
MessageBox ( GUIBASE_MSG ( " err_compile " ) , GUIBASE_COMMON ( " error " ) , MB_ICONERROR | MB_OK ) ;
2026-03-21 12:50:26 -05:00
}
else
{
2026-03-25 22:18:11 -05:00
//--- Deternminamos que archivo final se usa uno custom o el mismo pero con extension ?¿
2026-03-25 21:39:19 -05:00
const int res = MessageBox ( GUIBASE_MSG ( " msg_desea_usar_file_curr " ) , GUIBASE_COMMON ( " info " ) , MB_ICONQUESTION | MB_YESNO ) ;
2026-03-25 22:18:11 -05:00
if ( res = = IDNO ) // No se desea usar el archivo file curr le damos posibdad de seleccionar
2026-03-25 21:39:19 -05:00
{
string arr [ ] ;
if ( FileSelectDialog ( m_file_select_dialog_cap , AIDATATASKRUNER_PATH_FEATURES_EDITOR , " CSV files (*.csv)|*.csv " ,
2026-03-25 22:18:11 -05:00
( comon_folder ? FSD_COMMON_FOLDER : 0 ) , arr , NULL ) < 1 ) // no es boliatirio que exista
2026-03-25 21:39:19 -05:00
{
MessageBox ( GUIBASE_MSG ( " err_select_file " ) , GUIBASE_COMMON ( " error " ) , MB_ICONERROR | MB_OK ) ;
return ;
}
file_name_out = arr [ 0 ] ;
}
else
{
file_name_out = FileRemoveExtension ( file_name_out ) + " .csv " ; // solo quitamos la extension y lo ponemos csv
}
2026-03-25 22:18:11 -05:00
//---
2026-03-25 21:39:19 -05:00
const int fh = FileOpen ( file_name_out , FILE_WRITE | FILE_CSV | m_common_flag , 0 ) ;
2026-03-21 12:50:26 -05:00
if ( fh = = INVALID_HANDLE )
{
2026-03-25 21:39:19 -05:00
MessageBox ( GUIBASE_MSG ( " err_save_file " ) , GUIBASE_COMMON ( " error " ) , MB_ICONERROR | MB_OK ) ;
2026-03-21 12:50:26 -05:00
return ;
}
2026-07-07 13:38:29 -05:00
FileWriteString ( fh , csv ) ;
2026-03-21 12:50:26 -05:00
FileClose ( fh ) ;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CFeaturesCodeEditor : : OnLenguajeChange ( )
{
CBasicCodeEditor : : OnLenguajeChange ( ) ;
m_buttom_compile . LabelText ( m_language [ GUIBASE_COMPONENT_NAME ( m_buttom_compile ) ] ) ;
m_buttom_compile . Tooltip ( m_language . Tooltip ( GUIBASE_COMPONENT_NAME ( m_buttom_compile ) ) ) ;
m_buttom_compile . Update ( true ) ;
}
//+------------------------------------------------------------------+
# endif // AIDATATASKRUNER_UI_FEATURESEDITOR_FEAUTRESEDITOR_MQH