void Entity::Serialize(FileWriter & writer) { writer.WriteUnsignedInt(static_cast<unsigned int>(GetPos().X())); writer.WriteUnsignedInt(static_cast<unsigned int>(GetPos().Y())); writer.WriteUnsignedInt(static_cast<unsigned int>(m_components.size())); std::list<IComponent*>::iterator iter = m_components.begin(); while(iter != m_components.end()) { IComponent * component = *iter; writer.WriteUnsignedInt(component->GetComponentType()); component->Serialize(writer); iter++; } }
PVisualObject VisualObject::CreateVisualObject (shared_ptr<ObjectBase> obj, wxWindow *wx_parent) { PVisualObject vobj; shared_ptr<ObjectInfo> obj_info = obj->GetObjectInfo(); wxString type = obj->GetObjectTypeName(); // TO-DO: arreglar esto! // // El tipo de objeto se deberá indicar en el plugin // quizá sea conveniente dividir la macro COMPONENT("name",component) // estas tres: // WINDOW_COMPONENT // SIZER_COMPONENT // ABSTRACT_COMPONENT // y que se pueda consultar el tipo. IComponent *comp = obj->GetObjectInfo()->GetComponent(); if (comp) { int compType = comp->GetComponentType(); switch (compType) { case COMPONENT_TYPE_WINDOW: vobj = PVisualObject(new VisualWindow(obj,wx_parent)); break; case COMPONENT_TYPE_SIZER: vobj = PVisualObject(new VisualSizer(obj,wx_parent)); break; default: // items y forms vobj = PVisualObject(new VisualObject(obj)); break; } } else { vobj = PVisualObject(new VisualObject(obj)); wxLogError( wxT("Component for %s not found!"),obj->GetClassName().c_str() ); } return vobj; }
void VisualEditor::OnObjectSelected( wxFBObjectEvent &event ) { // It is only necessary to Create() if the selected object is on a different form if ( AppData()->GetSelectedForm() != m_form ) { Create(); } // Get the ObjectBase from the event PObjectBase obj = event.GetFBObject(); if ( !obj ) { // Strange... Debug::Print( wxT("The event object is NULL - why?") ); return; } // Make sure this is a visible object ObjectBaseMap::iterator it = m_baseobjects.find( obj.get() ); if ( m_baseobjects.end() == it ) { m_back->SetSelectedSizer( NULL ); m_back->SetSelectedItem( NULL ); m_back->SetSelectedObject( PObjectBase() ); m_back->SetSelectedPanel( NULL ); m_back->Refresh(); return; } // Save wxobject wxObject* item = it->second; int componentType = COMPONENT_TYPE_ABSTRACT; IComponent *comp = obj->GetObjectInfo()->GetComponent(); if ( comp ) { componentType = comp->GetComponentType(); // Fire selection event in plugin if ( !m_stopSelectedEvent ) { comp->OnSelected( item ); } } if ( componentType != COMPONENT_TYPE_WINDOW && componentType != COMPONENT_TYPE_SIZER ) { item = NULL; } // Fire selection event in plugin for all parents if ( !m_stopSelectedEvent ) { PObjectBase parent = obj->GetParent(); while ( parent ) { IComponent* parentComp = parent->GetObjectInfo()->GetComponent(); if ( parentComp ) { ObjectBaseMap::iterator parentIt = m_baseobjects.find( parent.get() ); if ( parentIt != m_baseobjects.end() ) { parentComp->OnSelected( parentIt->second ); } } parent = parent->GetParent(); } } // Look for the active panel - this is where the boxes will be drawn during OnPaint // This is the closest parent of type COMPONENT_TYPE_WINDOW PObjectBase nextParent = obj->GetParent(); while ( nextParent ) { IComponent* parentComp = nextParent->GetObjectInfo()->GetComponent(); if ( !parentComp ) { nextParent.reset(); break; } if ( parentComp->GetComponentType() == COMPONENT_TYPE_WINDOW ) { break; } nextParent = nextParent->GetParent(); } // Get the panel to draw on wxWindow* selPanel = NULL; if ( nextParent ) { it = m_baseobjects.find( nextParent.get() ); if ( m_baseobjects.end() == it ) { selPanel = m_back->GetFrameContentPanel(); } else { selPanel = wxDynamicCast( it->second, wxWindow ); } } else { selPanel = m_back->GetFrameContentPanel(); } // Find the first COMPONENT_TYPE_WINDOW or COMPONENT_TYPE_SIZER // If it is a sizer, save it wxSizer* sizer = NULL; PObjectBase nextObj = obj->GetParent(); while ( nextObj ) { IComponent* nextComp = nextObj->GetObjectInfo()->GetComponent(); if ( !nextComp ) { break; } if ( nextComp->GetComponentType() == COMPONENT_TYPE_SIZER ) { it = m_baseobjects.find( nextObj.get() ); if ( it != m_baseobjects.end() ) { sizer = wxDynamicCast( it->second, wxSizer ); } break; } else if ( nextComp->GetComponentType() == COMPONENT_TYPE_WINDOW ) { break; } nextObj = nextObj->GetParent(); } m_back->SetSelectedSizer( sizer ); m_back->SetSelectedItem( item ); m_back->SetSelectedObject( obj ); m_back->SetSelectedPanel( selPanel ); m_back->Refresh(); }
/** * Generates wxObjects from ObjectBase * * @param obj ObjectBase to generate. * @param parent wxWindow parent, necessary to instantiate a widget. * @param parentObject ObjectBase parent - not always the same as the wxparent (e.g. an abstract component). */ void VisualEditor::Generate( PObjectBase obj, wxWindow* wxparent, wxObject* parentObject ) { // Get Component PObjectInfo obj_info = obj->GetObjectInfo(); IComponent* comp = obj_info->GetComponent(); if ( NULL == comp ) { THROW_WXFBEX( wxString::Format( wxT("Component for %s not found!"), obj->GetClassName().c_str() ) ); } // Create Object wxObject* createdObject = comp->Create( obj.get(), wxparent ); wxWindow* createdWindow = NULL; wxSizer* createdSizer = NULL; switch ( comp->GetComponentType() ) { case COMPONENT_TYPE_WINDOW: createdWindow = wxDynamicCast( createdObject, wxWindow ); if ( NULL == createdWindow ) { THROW_WXFBEX( wxString::Format( wxT("Component for %s was registered as a window component, but this is not a wxWindow!"), obj->GetClassName().c_str() ) ); } SetupWindow( obj, createdWindow ); // Push event handler in order to respond to Paint and Mouse events createdWindow->PushEventHandler( new VObjEvtHandler( createdWindow, obj ) ); break; case COMPONENT_TYPE_SIZER: createdSizer = wxDynamicCast( createdObject, wxSizer ); if ( NULL == createdSizer ) { THROW_WXFBEX( wxString::Format( wxT("Component for %s was registered as a sizer component, but this is not a wxSizer!"), obj->GetClassName().c_str() ) ); } SetupSizer( obj, createdSizer ); break; default: break; } // Associate the wxObject* with the PObjectBase m_wxobjects.insert( wxObjectMap::value_type( createdObject, obj ) ); m_baseobjects.insert( ObjectBaseMap::value_type( obj.get(), createdObject ) ); // New wxparent for the window's children wxWindow* new_wxparent = ( createdWindow ? createdWindow : wxparent ); // Recursively generate the children for ( unsigned int i = 0; i < obj->GetChildCount(); i++ ) { Generate( obj->GetChild( i ), new_wxparent, createdObject ); } comp->OnCreated( createdObject, new_wxparent ); // If the created object is a sizer and the parent object is a window, set the sizer to the window if ( ( createdSizer != NULL && NULL != wxDynamicCast( parentObject, wxWindow ) ) || ( NULL == parentObject && createdSizer != NULL ) ) { wxparent->SetSizer( createdSizer ); if ( parentObject ) createdSizer->SetSizeHints( wxparent ); wxparent->SetAutoLayout(true); wxparent->Layout(); } }
bool CEntityManager::VisitNode(IHashString *searchString, IVisitor *visitorPattern) { static CHashString compType(_T("CEntity")); IDTOOBJECTMAP *entityMap = GetObjectMap(&compType); if(entityMap == NULL) { return true; } if (!visitorPattern) { return false; } IDTOOBJECTMAP::iterator osIter = entityMap->begin(); CEntity *entity; if (searchString != NULL) { for(; osIter != entityMap->end(); ++osIter) { entity = dynamic_cast<CEntity *>(osIter->second); if (entity == NULL) { m_ToolBox->SetErrorValue(ERR_NULL_POINTER); m_ToolBox->Log(LOGERROR, _T("Unable to cast IObject* to CEntity* \n")); return false; } if (CompareNames(searchString->GetString(), entity->GetEntityTypes()) ) { IComponent *visitComp = dynamic_cast<IComponent *>(osIter->second); if (visitComp != NULL) { visitorPattern->Visit(visitComp, true); } else { IHashString *typeName = visitComp->GetComponentType(); EngineGetToolBox()->Log(LOGWARNING, _T("component of type %s was used as IComponent and is not one.\n"), typeName); } } } } else { for(; osIter != entityMap->end(); ++osIter) { IComponent *visitComp = dynamic_cast<IComponent *>(osIter->second); if (visitComp != NULL) { visitorPattern->Visit(visitComp, true); } else { IHashString *typeName = visitComp->GetComponentType(); EngineGetToolBox()->Log(LOGWARNING, _T("component of type %s was used as IComponent and is not one.\n"), typeName); } } } return true; }