Exemplo n.º 1
0
void PHPCodeGenerator::GenVirtualEventHandlers( const EventVector& events, const wxString& eventHandlerPostfix )
{
	if ( events.size() > 0 )
	{
		// There are problems if we create "pure" virtual handlers, because some
		// events could be triggered in the constructor in which virtual methods are
		// execute properly.
		// So we create a default handler which will skip the event.
		m_source->WriteLn( wxEmptyString );
		m_source->WriteLn( wxT("// Virtual event handlers, overide them in your derived class") );

		std::set<wxString> generatedHandlers;
		for ( size_t i = 0; i < events.size(); i++ )
		{
			PEvent event = events[i];
			wxString aux = wxT("function ") + event->GetValue() + wxT("( $event ){");

			if (generatedHandlers.find(aux) == generatedHandlers.end())
			{
				m_source->WriteLn(aux);
				m_source->Indent();
				m_source->WriteLn(eventHandlerPostfix);
				m_source->Unindent();
				m_source->WriteLn(wxT("}"));

				generatedHandlers.insert(aux);
			}
			if( i < (events.size()-1) )  m_source->WriteLn();
		}
		m_source->WriteLn( wxEmptyString );
	}
}
void EventSheetEditor::ExpandAllGroups(bool open, CEditorEvent* pParent)
{
    EventVector* pEvents = this->m_pEventList;
    if(pParent)
    {
        if(pParent->m_type == GROUP_TYPE)
        {
            pParent->m_open(this) = open;
        }
        pEvents = &pParent->m_EventList;
    }
    EventVector::iterator e = pEvents->begin();
    for(; e!= pEvents->end(); e++)
    {
        ExpandAllGroups(open, *e);
    }
}
void EventSheetEditor::CreateEventSelectionVector(SelectedEventVector& pSelectedEventList,EventVector& EventList)
{
    for(int a = 0 ; a < EventList.size() ; a ++)
    {
        if(EventList[a]->m_select(this))
            pSelectedEventList.push_back(EventList[a]);

        CreateEventSelectionVector(pSelectedEventList, EventList[a]->m_EventList);
    }
}
void EventSheetEditor::CreateActionSelectionVector(SelectedActionVector& pSelectedActionList, EventVector& EventList)
{
    for(int a = 0 ; a < EventList.size() ; a ++)
    {
        for(int c = 0; c < EventList[a]->m_Actions.size(); c ++ )
            if(	EventList[a]->m_Actions[c]->m_select(this))
                pSelectedActionList.push_back(EventList[a]->m_Actions[c]);

        CreateActionSelectionVector(pSelectedActionList,EventList[a]->m_EventList);
    }
}
void EventSheetEditor::CreateConditionSelectionVector(SelectedConditionVector& pSelectedConditionList, EventVector& EventList)
{
    for(int a = 0 ; a < EventList.size() ; a ++)
    {
        for(int c = 0; c < EventList[a]->m_Conditions.size(); c ++ )
            if(	EventList[a]->m_Conditions[c]->m_select(this)
                    && !EventList[a]->m_Conditions[c]->m_Anim.m_bDestroyed)
                pSelectedConditionList.push_back(EventList[a]->m_Conditions[c]);

        CreateConditionSelectionVector(pSelectedConditionList,EventList[a]->m_EventList);
    }
}
Exemplo n.º 6
0
void PHPCodeGenerator::FindEventHandlers(PObjectBase obj, EventVector &events)
{
  unsigned int i;
  for (i=0; i < obj->GetEventCount(); i++)
  {
	PEvent event = obj->GetEvent(i);
	if (!event->GetValue().IsEmpty())
	  events.push_back(event);
  }

  for (i=0; i < obj->GetChildCount(); i++)
  {
	PObjectBase child = obj->GetChild(i);
	FindEventHandlers(child,events);
  }
}
Exemplo n.º 7
0
void PHPCodeGenerator::GenDestructor( PObjectBase class_obj, const EventVector &events )
{
	m_source->WriteLn();
	// generate function definition
	m_source->WriteLn( wxT("function __destruct( ){") );
	m_source->Indent();

	if ( m_disconnectEvents && !events.empty() )
	{
		GenEvents( class_obj, events, true );
	}

	// destruct objects
	GenDestruction( class_obj );

	m_source->Unindent();
	m_source->WriteLn( wxT("}") );
}
void copyState( ESMoL::State inputState, ESMoL::State outputState ) {

	UdmEngine::copyState( inputState, outputState );

	TransStartVector transStartVector = inputState.TransStart_kind_children();
	for( TransStartVector::iterator tsvItr = transStartVector.begin() ; tsvItr != transStartVector.end() ; ++tsvItr ) {
		ESMoL::TransStart inputTransStart = *tsvItr;
		ESMoL::TransStart outputTransStart = ESMoL::TransStart::Create( outputState );
		getTransConnectorMap().insert(  std::make_pair( inputTransStart, outputTransStart )  );
	}

	DataVector dataVector = inputState.Data_kind_children();
	for( DataVector::iterator dtvItr = dataVector.begin() ; dtvItr != dataVector.end() ; ++dtvItr ) {
		copyData(  *dtvItr, ESMoL::Data::Create( outputState )  );
	}

	EventVector eventVector = inputState.Event_kind_children();
	for( EventVector::iterator envItr = eventVector.begin() ; envItr != eventVector.end() ; ++envItr ) {
		copyEvent(  *envItr, ESMoL::Event::Create( outputState )  );
	}

	JunctionVector junctionVector = inputState.Junction_kind_children();
	for( JunctionVector::iterator jnvItr = junctionVector.begin() ; jnvItr != junctionVector.end() ; ++jnvItr ) {
		ESMoL::Junction inputJunction = *jnvItr;
		ESMoL::Junction outputJunction = ESMoL::Junction::Create( outputState );
		getTransConnectorMap().insert(  std::make_pair( inputJunction, outputJunction )  );
	}

	StateVector stateVector = inputState.State_kind_children();
	for( StateVector::iterator stvItr = stateVector.begin() ; stvItr != stateVector.end() ; ++stvItr ) {
		ESMoL::State inputSubState = *stvItr;
		ESMoL::State outputSubState = ESMoL::State::Create( outputState );
		getTransConnectorMap().insert(  std::make_pair( inputSubState, outputSubState )  );
		copyState( inputSubState, outputSubState );
	}

	ConnectorRefVector connectorRefVector = inputState.ConnectorRef_kind_children();
	for( ConnectorRefVector::iterator jnvItr = connectorRefVector.begin() ; jnvItr != connectorRefVector.end() ; ++jnvItr ) {
		ESMoL::ConnectorRef inputConnectorRef = *jnvItr;
		ESMoL::ConnectorRef outputConnectorRef = ESMoL::ConnectorRef::Create( outputState );
		getTransConnectorMap().insert(  std::make_pair( inputConnectorRef, outputConnectorRef )  );
		getConnectorRefList().push_back( inputConnectorRef );
	}

	TransitionVector transitionVector = inputState.Transition_kind_children();
	for( TransitionVector::iterator trvItr = transitionVector.begin() ; trvItr != transitionVector.end() ; ++trvItr ) {
		ESMoL::Transition inputTransition = *trvItr;

		ESMoL::TransConnector inputSrcTransConnector = inputTransition.srcTransition_end();
		TransConnectorMap::iterator tcmItr = getTransConnectorMap().find( inputSrcTransConnector );
		if ( tcmItr == getTransConnectorMap().end() ) {
			std::cerr << "WARNING:  transconnector does not map to copy" << std::endl;
			continue;
		}
		ESMoL::TransConnector outputSrcTransConnector = tcmItr->second;

		ESMoL::TransConnector inputDstTransConnector = inputTransition.dstTransition_end();
		tcmItr = getTransConnectorMap().find( inputDstTransConnector );
		if ( tcmItr == getTransConnectorMap().end() ) {
			std::cerr << "WARNING:  transconnector does not map to copy" << std::endl;
			continue;
		}
		ESMoL::TransConnector outputDstTransConnector = tcmItr->second;

		ESMoL::Transition outputTransition = ESMoL::Transition::Create( outputState );
		UdmEngine::copyTransition( inputTransition, outputTransition );

		outputTransition.srcTransition_end() = outputSrcTransConnector;
		outputTransition.dstTransition_end() = outputDstTransConnector;
	}
}
Exemplo n.º 9
0
void PHPCodeGenerator::GenEvents( PObjectBase class_obj, const EventVector &events, bool disconnect )
{
	if ( events.empty() )
	{
		return;
	}

	if( disconnect )
	{
		m_source->WriteLn( wxT("// Disconnect Events") );
	}
	else
	{
		m_source->WriteLn();
		m_source->WriteLn( wxT("// Connect Events") );
	}

	PProperty propName = class_obj->GetProperty( wxT("name") );
	if ( !propName )
	{
		wxLogError(wxT("Missing \"name\" property on \"%s\" class. Review your XML object description"),
			class_obj->GetClassName().c_str());
		return;
	}

	wxString class_name = propName->GetValue();
	if ( class_name.empty() )
	{
		wxLogError( wxT("Object name cannot be null") );
		return;
	}

	wxString base_class;
	wxString handlerName;

	PProperty propSubclass = class_obj->GetProperty( wxT("subclass") );
	if ( propSubclass )
	{
		wxString subclass = propSubclass->GetChildFromParent( wxT("name") );
		if ( !subclass.empty() )
		{
			base_class = subclass;
		}
	}

	if ( base_class.empty() )
		base_class = wxT("wx") + class_obj->GetClassName();

	if ( events.size() > 0 )
	{
		for ( size_t i = 0; i < events.size(); i++ )
		{
			PEvent event = events[i];

			handlerName = event->GetValue();

			wxString templateName = wxString::Format( wxT("connect_%s"), event->GetName().c_str() );

			PObjectBase obj = event->GetObject();
			if ( !GenEventEntry( obj, obj->GetObjectInfo(), templateName, handlerName, disconnect ) )
			{
				wxLogError( wxT("Missing \"evt_%s\" template for \"%s\" class. Review your XML object description"),
					templateName.c_str(), class_name.c_str() );
			}
		}
	}
}
Exemplo n.º 10
0
void PHPCodeGenerator::GenerateInheritedClass( PObjectBase userClasses, PObjectBase form )
{
	if (!userClasses)
	{
		wxLogError(wxT("There is no object to generate inherited class"));
		return;
	}

	if ( wxT("UserClasses") != userClasses->GetClassName() )
	{
		wxLogError(wxT("This not a UserClasses object"));
		return;
	}

	wxString type = userClasses->GetPropertyAsString( wxT("type") );

	// Start file
	wxString code = GetCode( userClasses, wxT("file_comment") );
	m_source->WriteLn( code );
	m_source->WriteLn( wxEmptyString );

	code = GetCode( userClasses, wxT("source_include") );
	m_source->WriteLn( code );
	m_source->WriteLn( wxEmptyString );

	code = GetCode( userClasses, wxT("class_decl") );
	m_source->WriteLn( code );
	m_source->Indent();

	code = GetCode( userClasses, type + wxT("_cons_def") );
	m_source->WriteLn( code );

	// Do events
	EventVector events;
	FindEventHandlers( form, events );

	if ( events.size() > 0 )
	{
		code = GetCode( userClasses, wxT("event_handler_comment") );
		m_source->WriteLn( code );

		std::set<wxString> generatedHandlers;
		for ( size_t i = 0; i < events.size(); i++ )
		{
			PEvent event = events[i];
			if ( generatedHandlers.find( event->GetValue() ) == generatedHandlers.end() )
			{
				m_source->WriteLn( wxString::Format( wxT("function %s( event ){"),  event->GetValue().c_str() ) );
				m_source->Indent();
				m_source->WriteLn( wxString::Format( wxT("// TODO: Implement %s"), event->GetValue().c_str() ) );
				m_source->Unindent();
				m_source->WriteLn( wxT("}") );
				m_source->WriteLn( wxEmptyString );
				generatedHandlers.insert(event->GetValue());
			}
		}
		m_source->WriteLn( wxEmptyString );
	}

	m_source->Unindent();
}