Exemplo n.º 1
0
CImportXMLDlg::CImportXMLDlg(wxWindow* parent) : wxDialog(parent, wxID_ANY, wxString(_("Import XML Settings"))),
                                                  importUnderGroup(false), 
                                                  importPasswordsOnly(false)
{
  enum { TopMargin = 20, BottomMargin = 20, SideMargin = 30, RowSeparation = 10, ColSeparation = 20};
  
  wxSizerFlags borderFlags = wxSizerFlags().Border(wxLEFT|wxRIGHT, SideMargin).Expand();
  wxSizerFlags separatorFlags = wxSizerFlags().Border(wxLEFT|wxRIGHT, SideMargin/2).Expand();
  
  wxBoxSizer* dlgSizer = new wxBoxSizer(wxVERTICAL);
  dlgSizer->AddSpacer(TopMargin);

  dlgSizer->Add(new wxStaticText(this, wxID_ANY, _("XML file to import:")), borderFlags);
  dlgSizer->AddSpacer(RowSeparation/2);
  COpenFilePickerValidator validator(filepath);
  dlgSizer->Add(new wxFilePickerCtrl(this, wxID_ANY, wxEmptyString, 
                                          _("Please Choose a XML File to Import"), 
                                          _("XML files (*.xml)|*.xml"), 
                                          wxDefaultPosition, wxDefaultSize, 
                                          wxFLP_DEFAULT_STYLE | wxFLP_USE_TEXTCTRL, 
                                          validator), borderFlags);
  dlgSizer->AddSpacer(RowSeparation);

  dlgSizer->Add(new wxStaticLine(this), separatorFlags);
  dlgSizer->AddSpacer(RowSeparation);
  
  wxBoxSizer* horzSizer = new wxBoxSizer(wxHORIZONTAL);
  horzSizer->Add(CheckBox(_("Import under Group"), &importUnderGroup), wxSizerFlags().Proportion(0));
  horzSizer->AddSpacer(ColSeparation);
  horzSizer->Add(TextCtrl(&groupName), wxSizerFlags().Proportion(1));
  dlgSizer->Add(horzSizer, borderFlags);
  dlgSizer->AddSpacer(RowSeparation);
  
  dlgSizer->Add(CheckBox(_("Import to change passwords of existing entries ONLY"), &importPasswordsOnly),
                    borderFlags);
  dlgSizer->AddSpacer(RowSeparation);
  
  dlgSizer->Add(new wxStaticLine(this), separatorFlags);
  dlgSizer->AddSpacer(RowSeparation);
  
  dlgSizer->Add(CreateStdDialogButtonSizer(wxOK|wxCANCEL|wxHELP), borderFlags);
  dlgSizer->AddSpacer(BottomMargin);
  
  SetSizerAndFit(dlgSizer);
}
Exemplo n.º 2
0
errorType StartleServer::ProcessUser1Record(wxSocketBase &sock) //override this function only
{
errorType rv=errNone;
wxString s;
//StartleRecord stl;
wxInt16 recType;
wxInt16 queuedFlag;
wxUint16 atTick;

// Can't use ReadMsg as this is a wx extension
//have already read the GSISocketUser1 id, which is why we are here
//1)Command
//2)flag

    TextCtrl()->AppendText("\n\n--------- New startle record ----------\n");


    //sock.SetFlags(wxSOCKET_WAITALL);
/*--------------Read the STL Type field----------------*/
    sock.Read(&recType,sizeof (recType));
    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
        return(sockErr.GetErrorCode());
	}

	s.Printf("Type=%i\n",recType);
    TextCtrl()->AppendText(s);

#if STL_DEBUG_USING_XXX //xxx functions read their own fixed length data
queuedFlag;
atTick;
#else

/*----------Read the STL QUEUED/IMMEDIATE Flag field--------------------*/
    sock.Read(&queuedFlag,sizeof (queuedFlag));
    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
        return(sockErr.GetErrorCode());
	}

	s.Printf("flag=%i: ",queuedFlag);
    TextCtrl()->AppendText(s);

    if( (queuedFlag != STL_QUEUED) && (queuedFlag != STL_IMMEDIATE) )
    {
        TextCtrl()->AppendText("\n--- Flag error! ---\n");
        rv=errParameter;
    }
	else
	{
		if(queuedFlag==	STL_QUEUED)
			TextCtrl()->AppendText("Queued\n");
		else
			TextCtrl()->AppendText("Immediate\n");
	}
/*-----------------------------------------------------*/

/*--------------Read the atTick field----------------*/
    sock.Read(&atTick,sizeof(atTick));
    if(sock.Error())
	{
		MapWxSocketError sockErr(sock.LastError());
        return(sockErr.GetErrorCode());
	}

	s.Printf("at tick=%i \n",atTick);
    TextCtrl()->AppendText(s);
//----Read all fixed record elements---------------------------------------------

    TextCtrl()->AppendText("\n---------- Processing StartleRecord ----------\n");

    if(recType !=STL_COMMAND_OPEN_DEVICE && ! IsOpen())
    {
        //device isn't open and we are trying to send a command
        //return an error to the client
        //STLSocketReturnData sr(GSIClient(),(enum GSISocketReturnValue) GSINoNode);      //instantiate

        GSISocketReturnData sr(sock,GSISocketReturnData::GSI_NO_DEVICE);      //instantiate
        s.Printf("\n------------------- Failed: %s -----------------\n\n",sr.GetErrorString());
        TextCtrl()->AppendText(s);
        return errFail;
    }
#endif

#warning ("Need to test sending commands with no Device Opened")
	try
	{

	/*------------perform any Type specific transforms, or operations ------*/
		switch (recType)
		{
//STL_COMMAND_RESET and STL_COMMAND_SET_AMPLITUDE use the current
//method of communication. Work is done by StartleFrame::xxx functions
		case STL_COMMAND_RESET:
			{
				STLServerCommandResetXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
		case STL_COMMAND_SET_AMPLITUDE_SPL:        //requires 1023=0, 0=1023.
			{
				STLServerCommandSetAmplitudeSPLXXX Cmd(sock,GetAmplitudeLUT());
				Cmd.SetStatusText(TextCtrl());

				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
//New commands tested through the socket up to here
		case STL_COMMAND_SET_FREQUENCY:
			{
				STLServerCommandSetFrequencyXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

			//rv=GetStartleFrame()->SetFrequency(sock,queuedFlag,atTick); //Hz is coming through the socket
			break;
		case STL_COMMAND_ACQUIRE:
			{
				STLServerCommandAcquireXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

		case STL_COMMAND_WAIT_FOR_COMPLETION:
			{
				STLServerCommandWaitForCompletionXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
		case STL_COMMAND_SET_CHANNEL:
			{
				STLServerCommandSetChannelXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());

				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

//New commands implemented up to here
		case STL_COMMAND_SET_NOISE_AMPLITUDE_SPL:
			{
				STLServerCommandSetNoiseAmplitudeSPLXXX Cmd(sock,GetNoiseAmplitudeLUT());
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
		case STL_COMMAND_EXECUTE:
			{
				STLServerCommandExecuteXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

		case STL_COMMAND_OPEN_DEVICE:  //param0=comport number 1-6
			{
				STLServerCommandOpenDeviceXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				//rv=GetGSIFrame().ProcessServerCommand(Cmd);
#warning ("Need to update state of GSIFrame/StartleFrame with device information")

#if STL_DEBUG_USING_XXX
				//will stop ProcessServerCommandRead()
				//from reading fixed length records
				//so must add them here. Though not reqd for Open()
#endif
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;
			//rv=GetStartleFrame()->OpenDevice(sock); //inherited from GSIFrame
			break;
		case STL_COMMAND_CLOSE_DEVICE:  //param0=comport number 1-6
			{
				STLServerCommandCloseDeviceXXX Cmd(sock);
				Cmd.SetStatusText(TextCtrl());
				rv=GetStartleFrameRef().ProcessServerCommand(Cmd,sock);
				if(rv)
					return rv;
			}
			break;

			//rv=GetStartleFrame()->CloseDevice(sock);	//inherited from GSIFrame
			break;
		case STL_COMMAND_SET_AMPLITUDE_LUT_VALUE:           //set an element of the LUT p0=index, p1=value
			//rv=GetStartleFrame()->SetAmplitudeLUTValue(sock);
			break;
		case STL_COMMAND_SET_NOISE_AMPLITUDE_LUT_VALUE:           //set an element of the LUT p0=index, p1=value
			//rv=GetStartleFrame()->SetNoiseAmplitudeLUTValue(sock);
			break;
		default:
			//only instantiate the STLSocketReturnData here as it will write the code in it's dtor
			//STLSocketReturnData sr(*sock,GSISocketReturnData:: GSI_PARAM_ERROR,false);      //instantiate
			GSISocketReturnData sr(sock,GSISocketReturnData:: GSI_PARAM_ERROR,false);      //instantiate
			TextCtrl()->AppendText("\n-------- Bad Command ---------\n");
			rv=errParameter;        //this needs to return a SocketReturn
			break;
		}
	/*---------------------------------------------------------*/
		//TextCtrl()->AppendText(s);
		TextCtrl()->AppendText("\n--------Finished processing record---------\n");
		TextCtrl()->AppendText("\n-------------------------------------------\n");
	}
	catch(gsException &exc)
	{
        wxString s;
        s.Printf("Exception: %s. \nError code=%i %s",exc.GetUserString(),exc.GetErrorCode(),exc.GetString());
        TextCtrl()->AppendText(s);
		return exc.GetErrorCode();
	}
    return rv;
}