00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "StdAfx.h"
00022 #include "SFBonExtension.h"
00023 #include "BON2Component.h"
00024
00025 namespace BON
00026 {
00027
00028 using namespace SF_BON;
00029
00030
00031
00032
00033
00034
00035
00036 Component::Component()
00037 : m_bIsInteractive( false )
00038 {
00039 }
00040
00041 Component::~Component()
00042 {
00043 finalize( m_project );
00044 m_project = NULL;
00045 }
00046
00047
00048
00049
00050
00051 void Component::initialize( Project& project )
00052 {
00053
00054
00055 }
00056
00057
00058
00059
00060
00061 void Component::finalize( Project& project )
00062 {
00063
00064
00065 }
00066
00067
00068
00069
00070
00071 void Component::invoke( Project& project, const std::set<FCO>& setModels, long lParam )
00072 {
00073 #ifdef SUPPORT_OLD_INVOKE
00074 Object focus;
00075 invokeEx( project, focus, setModels, lParam );
00076 #else
00077 if ( m_bIsInteractive )
00078 AfxMessageBox("This BON2 Component does not support the obsolete invoke mechanism!");
00079 #endif
00080 }
00081
00082
00083
00084
00085
00086 void Component::invokeEx( Project& project, FCO& currentFCO, const std::set<FCO>& setSelectedFCOs, long lParam )
00087 {
00088 Compound root = Compound(currentFCO);
00089
00090 if(!root) {
00091 AfxMessageBox("Interpretation must start from a Compound model!");
00092 return;
00093 }
00094
00095 std::string filebase = root->getName();
00096 std::string cfile = filebase + ".c";
00097 std::string hfile = filebase + ".h";
00098
00099 std::set<Primitive> primitives;
00100 root->traverse(primitives);
00101
00102 FILE *fpt = fopen(hfile.c_str(),"wt");
00103 if(!fpt) {
00104 AfxMessageBox(CString("Error opening file ") + hfile.c_str());
00105 return;
00106 }
00107
00108 PrimitiveImpl::writeScriptProto(fpt);
00109 PrimitiveImpl::writeContextDefs(fpt);
00110 ParamImpl::writeGlobals(fpt);
00111 fprintf(fpt,"\n");
00112
00113 {
00114 for ( std::set<Primitive>::iterator it = primitives.begin() ; it != primitives.end() ; it++ )
00115 (*it)->writeContextCreate(fpt);
00116 }
00117
00118 fclose(fpt);
00119
00120 fpt = fopen(cfile.c_str(),"wt");
00121 if(!fpt) {
00122 AfxMessageBox("Error opening file " + CString(cfile.c_str()));
00123 return;
00124 }
00125
00126 fprintf(fpt,"#include <string.h>\n");
00127 fprintf(fpt,"#include <mgk60.h>\n");
00128 fprintf(fpt,"#include \"%s\"\n\n",hfile);
00129
00130 ParamImpl::writeGlobals(fpt,false);
00131 fprintf(fpt,"\n");
00132
00133 {
00134 for ( std::set<Primitive>::iterator it = primitives.begin() ; it != primitives.end() ; it++ )
00135 (*it)->writeContextCreate(fpt,false);
00136 }
00137 fprintf(fpt,"\n");
00138
00139
00140
00141 fprintf(fpt,"\nvoid register_scripts()\n{\n");
00142 PrimitiveImpl::writeScriptRegs(fpt);
00143 fprintf(fpt,"}\n\n");
00144
00145
00146 fprintf(fpt,"\nvoid build()\n{\n");
00147
00148 {
00149 for ( std::set<Primitive>::iterator it = primitives.begin() ; it != primitives.end() ; it++ )
00150 (*it)->writeActorCreate(fpt);
00151 }
00152 fprintf(fpt,"\n");
00153
00154 {
00155 for ( std::set<Primitive>::iterator it = primitives.begin() ; it != primitives.end() ; it++ )
00156 (*it)->writeSetContext(fpt);
00157 }
00158 fprintf(fpt,"\n");
00159
00160 {
00161 for ( std::set<Primitive>::iterator it = primitives.begin() ; it != primitives.end() ; it++ )
00162 (*it)->writeActorConnect(fpt);
00163 }
00164
00165 fprintf(fpt,"}\n");
00166 fclose(fpt);
00167
00168 AfxMessageBox(CString(cfile.c_str()) + " and " + hfile.c_str() + " generated");
00169 }
00170
00171
00172
00173
00174
00175 void Component::objectInvokeEx( Project& project, Object& currentObject, const std::set<Object>& setSelectedObjects, long lParam )
00176 {
00177 if ( m_bIsInteractive )
00178 AfxMessageBox("This BON2 Component does not support objectInvokeEx method!");
00179 }
00180
00181
00182
00183
00184 Util::Variant Component::getParameter( const std::string& strName )
00185 {
00186
00187
00188
00189 return Util::Variant();
00190 }
00191
00192 void Component::setParameter( const std::string& strName, const Util::Variant& varValue )
00193 {
00194
00195
00196 }
00197
00198 #ifdef GME_ADDON
00199
00200
00201
00202
00203 void Component::globalEventPerformed( globalevent_enum event )
00204 {
00205
00206
00207
00208 }
00209
00210
00211
00212
00213 void Component::objectEventPerformed( Object& object, unsigned long event, VARIANT v )
00214 {
00215
00216
00217 }
00218
00219 #endif GME_ADDON
00220
00221
00222 };
00223
00224