void wxGISApplicationBase::LoadCommands(wxXmlNode* pRootNode)
{
	wxXmlNode *child = pRootNode->GetChildren();
	unsigned int nCmdCounter(0);
	while(child)
	{
		wxString sName = child->GetAttribute(wxT("name"), wxT(""));
		if(!sName.IsEmpty())
		{
			wxObject *obj = wxCreateDynamicObject(sName);
			wxGISCommand *pCmd = dynamic_cast<wxGISCommand*>(obj);//wxDynamicCast(obj, wxGISCommand);//
			if(pCmd)
			{
				for(unsigned char i = 0; i < pCmd->GetCount(); i++)
				{
					wxObject *newobj = wxCreateDynamicObject(sName);
					wxGISCommand *pNewCmd = dynamic_cast<wxGISCommand*>(newobj);//wxDynamicCast(newobj, wxGISCommand);//
					if(pNewCmd && pNewCmd->OnCreate(this))
					{
						pNewCmd->SetId(ID_PLUGINCMD + nCmdCounter);
						pNewCmd->SetSubType(i);
						//TODO: check doubles
                        m_CommandArray.Add(pNewCmd);
						nCmdCounter++;
					}
				}
				wxDELETE(pCmd);
			}
		}
		child = child->GetNext();
	}
}
Esempio n. 2
0
/****************************************************************************
PARAMETERS:
className       - Name of the applet class to create an object for
size            - Initial size of the applet to be created

RETURNS:
Pointer to the wxApplet created, or NULL if unable to create the applet.

REMARKS:
This function is used to create new wxApplet objects dynamically based on the
class name as a string. This allows instances of wxApplet classes to be
created dynamically based on string values embedded in the custom tags of an
HTML page.
****************************************************************************/
wxApplet *wxHtmlAppletWindow::CreateApplet(
    const wxString& classId,
    const wxString& iName,
    const wxHtmlTag& params,
    const wxSize& size)
{
    // Dynamically create the class instance at runtime
    wxObject *obj = wxCreateDynamicObject(classId.c_str());
    wxApplet *applet = wxDynamicCast(obj,wxApplet);
    if (!applet)
        return NULL;
    if (!applet->Create(this,params,size)) {
        delete applet;
        return NULL;
        }
    else {
        // do some fixups on the size if its screwed up
        wxSize nsize = applet->GetBestSize();
        if (nsize.x < size.x) nsize.x = size.x;
        if (nsize.y < size.y) nsize.y = size.y;
        applet->SetSize(nsize);
        }

    m_AppletList.Append(iName,(wxObject*)applet);
    return applet;
}
Esempio n. 3
0
IGPToolSPtr wxGISGPToolManager::GetTool(wxString sToolName, IGxCatalog* pCatalog)
{
    if(sToolName.IsEmpty())
        return IGPToolSPtr();
    std::map<wxString, TOOLINFO>::const_iterator it = m_ToolsMap.find(sToolName);
    if(it == m_ToolsMap.end())
        return IGPToolSPtr();

    wxObject *pObj = wxCreateDynamicObject(it->second.sClassName);
    IGPToolSPtr pRetTool(dynamic_cast<IGPTool*>(pObj));
    if(it->second.pTool)
    {
        if(!it->second.pTool->GetCatalog())
            it->second.pTool->SetCatalog(pCatalog);

        if(pRetTool)
        {
            pRetTool->Copy(it->second.pTool.get());
            m_ToolsMap[sToolName].pTool = pRetTool;
            return pRetTool;
        }
        else
            return IGPToolSPtr();
    }

    if(!pRetTool)
    {
        TOOLINFO inf = {wxEmptyString, 0, IGPToolSPtr()};
        m_ToolsMap[sToolName] = inf;
        return IGPToolSPtr();
    }
    pRetTool->SetCatalog(pCatalog);
    m_ToolsMap[sToolName].pTool = pRetTool;
	return pRetTool;
}
Esempio n. 4
0
void wxXmlSerializer::DeserializeObjects(xsSerializable* parent, wxXmlNode* node)
{
    wxASSERT(m_pRoot);
    if(!m_pRoot)return;

	xsSerializable *pItem;

	wxXmlNode* projectNode = node->GetChildren();
	while(projectNode)
	{
		if(projectNode->GetName() == wxT("object"))
		{
#if wxVERSION_NUMBER < 2900
		    pItem = (xsSerializable*)wxCreateDynamicObject(projectNode->GetPropVal(wxT("type"), wxT("")));
#else
		    pItem = (xsSerializable*)wxCreateDynamicObject(projectNode->GetAttribute(wxT("type"), wxT("")));
#endif
			if(pItem)
			{
			    if(parent)
			    {
			        parent->AddChild(pItem);
			    }
			    else
                    m_pRoot->AddChild(pItem);

				pItem->DeserializeObject(projectNode);
				// id could change so we must update the IDs map
				m_mapUsedIDs[pItem->GetId()] = pItem;

				// deserialize child objects
				DeserializeObjects(pItem, projectNode);
			}
		}
		else if(projectNode->GetName() == m_sRootName + wxT("_properties"))
		{
		    m_pRoot->DeserializeObject(projectNode->GetChildren());
		}

		projectNode = projectNode->GetNext();
	}
}
Esempio n. 5
0
void xsDynObjPropIO::Read(xsProperty *property, wxXmlNode *source)
{
    wxXmlNode *objectNode = source->GetChildren();

    if( objectNode && (objectNode->GetName() == wxT("object")) )
    {
        *(xsSerializable**)(property->m_pSourceVariable) = (xsSerializable*)wxCreateDynamicObject(objectNode->GetPropVal(wxT("type"), wxT("")));

        xsSerializable* object = *(xsSerializable**)(property->m_pSourceVariable);
        if(object)
        {
            object->DeserializeObject(objectNode);
        }
    }
}
Esempio n. 6
0
wxGISGPToolManager::wxGISGPToolManager(void) : m_nRunningTasks(0)
{
	m_bIsOk = false;
	wxGISAppConfig oConfig = GetConfig();
	if(!oConfig.IsOk())
		return;

    m_nMaxTasks = oConfig.ReadInt(enumGISHKCU, TOOLBX_NAME + wxString(wxT("/tools/max_tasks")), wxThread::GetCPUCount());
#ifdef __WXMSW__
    m_sGeoprocessPath = oConfig.Read(enumGISHKCU, TOOLBX_NAME + wxString(wxT("/tools/gp_exec")), wxString(wxT("wxGISGeoprocess.exe")));
#else
    m_sGeoprocessPath = oConfig.Read(enumGISHKCU, TOOLBX_NAME + wxString(wxT("/tools/gp_exec")), wxString(wxT("/usr/local/bin/wxgis/wxGISGeoprocess")));
#endif
	wxXmlNode *pToolsNode = oConfig.GetConfigNode(enumGISHKCU, TOOLBX_NAME + wxString(wxT("/tools")));
	if(!pToolsNode)
		return;

	wxXmlNode *pChild = pToolsNode->GetChildren();
    while (pChild)
    {
        wxString sName = pChild->GetAttribute(wxT("object"), NONAME);
        if(sName.IsEmpty() || sName.CmpNoCase(NONAME) == 0)
        {
            pChild = pChild->GetNext();
            continue;
        }

        int nCount = wxAtoi(pChild->GetAttribute(wxT("count"), wxT("0")));
        wxString sCmdName = pChild->GetAttribute(wxT("name"), NONAME);

	    wxObject *pObj = wxCreateDynamicObject(sName);
        IGPToolSPtr pRetTool(dynamic_cast<IGPTool*>(pObj));
	    if(pRetTool)
	    {
            sCmdName = pRetTool->GetName();
			TOOLINFO info = {sName, nCount, pRetTool};
			m_ToolsMap[sCmdName] = info;
			m_ToolsPopularMap.insert(std::make_pair(nCount, sCmdName));
        }
        else
            wxLogError(_("Create %s object failed!"), sName.c_str());
        pChild = pChild->GetNext();
    }
	m_bIsOk = true;
}
Esempio n. 7
0
bool wxGISNetworkService::Start(IServerApplication* pApp, wxXmlNode* pConfig)
{
    m_pConfig = pConfig;
    m_pApp = pApp;

	if(pConfig == NULL || pConfig->GetName() != wxT("network"))
		return false;

	//Start out thread
	wxLogDebug(wxT("Start out thread"));
	m_pMsgOutThread = new wxMsgOutThread(this);
	if(!CreateAndRunThread(m_pMsgOutThread, wxT("wxGISNetworkService"), wxT("Out messages")))
		return false;
	else
		wxLogMessage(wxString::Format(_("wxGISNetworkService: %s Queue thread 0x%lx started"), wxT("Out messages"), m_pMsgOutThread->GetId()));

    m_nMaxConnectoinCount = wxAtoi(pConfig->GetPropVal(wxT("max_conn"), wxT("10")));
    m_sServerName = pConfig->GetPropVal(wxT("server_name"), wxT("Nemo"));

	wxXmlNode *child = pConfig->GetChildren();
	while(child) 
	{
		wxString sName = child->GetPropVal(wxT("name"), wxT(""));
		if(!sName.IsEmpty())
		{			
			wxObject *pObj = wxCreateDynamicObject(sName);
			INetworkPlugin *pPlugin = dynamic_cast<INetworkPlugin*>(pObj);
			if(pPlugin && pPlugin->Start(this, child))
			{
				m_NetworkPluginArray.push_back( pPlugin );
				wxLogMessage(_("wxGISNetworkService: Plugin %s initialize"), sName.c_str());
			}
			else
				wxLogError(_("wxGISNetworkService: Error initializing plugin %s"), sName.c_str());
		}
		child = child->GetNext();
	}	

	INetMessageProcessor* pNetMessageProcessor = dynamic_cast<INetMessageProcessor*>(m_pApp);
	if(pNetMessageProcessor)
		pNetMessageProcessor->AddMessageReceiver(wxT("bye"), static_cast<INetMessageReceiver*>(this));

	wxLogMessage(_("wxGISNetworkService: Service started"));
    return true;
}
Esempio n. 8
0
/****************************************************************************
PARAMETERS:
classId       - Name of the Plugin class to create an object for

RETURNS:
Pointer to the wxplugIn created, or NULL if unable to create the PlugIn.

REMARKS:
This function is used to create new wxPlugIn objects dynamically based on the
class name as a string. This allows instances of wxPlugIn classes to be
created dynamically based on string values embedded in the custom tags of an
HTML page.
****************************************************************************/
bool wxHtmlAppletWindow::CreatePlugIn(
    const wxString& classId,
    const wxString& cmdLine)
{
    // Dynamically create the class instance at runtime, execute it
    // and then destroy it.
    wxObject *obj = wxCreateDynamicObject(classId.c_str());
    wxPlugIn *plugIn = wxDynamicCast(obj,wxPlugIn);
    if (!plugIn)
        return false;
    if (!plugIn->Create(this)) {
        delete plugIn;
        return false;
        }
    plugIn->Run(cmdLine);
    delete plugIn;
    return true;
}
Esempio n. 9
0
bool ArcApp::MakeFactory()
{
    wxString type = m_archive.AfterLast(_T('.'));
    wxString name = _T("wx") + type.Left(1).Upper() +
                    type.Mid(1).Lower() + _T("ClassFactory");

    wxObject *pObj = wxCreateDynamicObject(name);
    wxArchiveClassFactory *pcf = wxDynamicCast(pObj, wxArchiveClassFactory);

    if (pcf) {
        m_factory.reset(pcf);
    } else {
        wxLogError(_T("can't handle '%s' archives"), type.c_str());
        delete pObj;
    }

    return pcf != NULL;
}
Esempio n. 10
0
void wxGISApplication::OnAppOptions(void)
{
    //read the config node for property pages and its names
	wxGISAppConfig oConfig = GetConfig();
	if(!oConfig.IsOk())
    {
        wxMessageBox(_("Get config failed!"), _("Error"), wxICON_ERROR | wxOK );
        return;
    }

    wxXmlNode *pPPXmlNode = oConfig.GetConfigNode(enumGISHKCU, GetAppName() + wxString(wxT("/propertypages")));
    if(!pPPXmlNode)
    {
        wxMessageBox(_("No Property Pages"), _("Error"), wxICON_ERROR | wxOK );
        return;
    }
    //load pages to the dialog and show
    wxPropertySheetDialog PropertySheetDialog;
    //(this, wxID_ANY, _("Options"), wxDefaultPosition, wxSize( 480,600 ), wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER);
    if (!PropertySheetDialog.Create(this, wxID_ANY, _("Options"), wxDefaultPosition, wxSize( 480,600 ), wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER))
        return;
    //PropertySheetDialog.SetMinSize( wxSize( 480,600 ));
    //PropertySheetDialog.SetSizeHints( wxSize( 480,600 ), wxDefaultSize );
    //PropertySheetDialog. SetClientSize( wxSize( 480,600 ));

    PropertySheetDialog.SetIcon(options_xpm);

    PropertySheetDialog.CreateButtons(wxOK|wxCANCEL);

    wxWindow* pParentWnd = static_cast<wxWindow*>(PropertySheetDialog.GetBookCtrl());
    // Add page
    wxXmlNode *pPropPageNode = pPPXmlNode->GetChildren();
    while(pPropPageNode)
    {
 		wxString sClass = pPropPageNode->GetAttribute(wxT("class"), ERR);
	    wxObject *obj = wxCreateDynamicObject(sClass);
		IPropertyPage *pPage = wxStaticCast(obj, IPropertyPage);//static_cast<IPropertyPage*>(obj);
		if(pPage != NULL)
		{
            if(pPage->Create(this, PropertySheetDialog.GetBookCtrl(), wxID_ANY))
            {
                wxPanel* panel = static_cast<wxPanel*>(pPage);
                if(panel)
                    PropertySheetDialog.GetBookCtrl()->AddPage(panel, pPage->GetPageName());
            }
        }
        pPropPageNode = pPropPageNode->GetNext();
    }

    //PropertySheetDialog.LayoutDialog();

    if(PropertySheetDialog.ShowModal() == wxID_OK)
    {
        //apply changes and exit
        for(size_t i = 0; i < PropertySheetDialog.GetBookCtrl()->GetPageCount(); ++i)
        {
            IPropertyPage *pPage = dynamic_cast<IPropertyPage*>(PropertySheetDialog.GetBookCtrl()->GetPage(i));// wxDynamicCast(PropertySheetDialog.GetBookCtrl()->GetPage(i), IPropertyPage);//
            if(pPage)
                pPage->Apply();
        }
    }
}