Пример #1
0
void MainWindow::buildDeviceMenu(DRUID::MenuPtr sguiMenu, wxMenu * intoMenu)
{
	wxColour darkFg(DRUID_COLOUR_FOREGROUND_DARK);

	wxSize btnMinSize(60, 40);
	wxSize btnMaxSize(230, 180);

	MenuHotKeysUsedMap hotKeys;

	SUIWindow* buttonWindow = newSUIWindow(sguiMenu->uid(), menu_id_counter);

	wxBoxSizer * menuSizer = new wxBoxSizer(wxVERTICAL);


	DRUID::MenuPtr parentMenu = sguiMenu->parent();
	unsigned int numRows = sguiMenu->size();

	if (parentMenu)
	{
		numRows += 2;
	}

	wxGridSizer * btnSizer = new wxGridSizer(numRows, 2, 0, 0);




	btnSizer->SetMinSize(400, 200);

	if (! parentMenu)
	{
		menuSizer->Add(new wxStaticText( buttonWindow, wxID_ANY, wxT("  ") ),
				                    0,
				                    wxALIGN_CENTER );
	} else {

		menuSizer->Add(new wxStaticText( buttonWindow, wxID_ANY, DRUID_STDSTRING_TOWX(sguiMenu->name())),
		                    0,
		                    wxALIGN_CENTER );

		wxString upStr(wxT("Back to "));
		upStr += DRUID_STDSTRING_TOWX(parentMenu->name());
		wxButton * btn = new wxButton(buttonWindow, menu_id_counter++, upStr);
		btn->SetHelpText(upStr);
		btn->SetForegroundColour(darkFg);
		btn->SetMinSize(btnMinSize);
		btn->SetMaxSize(btnMaxSize);


		btn->Connect(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,
							wxCommandEventHandler(MainWindow::OnUpMenu),
									new UpLevelClickUserData(sguiMenu),
									this
							);


		wxBoxSizer * btnLabelSizer = new wxBoxSizer(wxHORIZONTAL);
		btnLabelSizer->Add(new wxStaticBitmap(buttonWindow, wxID_ANY, up_icon),
				wxSizerFlags(0).Align(wxALIGN_CENTER));

		btnLabelSizer->Add(btn, wxSizerFlags(1).Expand().Align(wxALIGN_CENTER));

		btnSizer->Add(btnLabelSizer, wxSizerFlags(1).Expand().Align(wxALIGN_CENTER));
		btnSizer->Add(new wxStaticText(buttonWindow, wxID_ANY, wxT(" ")),
						wxSizerFlags(3).Align(wxALIGN_CENTER).Border(
								wxLEFT, 5));

		btnSizer->AddSpacer(0);
		btnSizer->AddSpacer(0);

	}

	for (unsigned int i = 0; i < sguiMenu->size(); i++)
	{
		unsigned int elementId = menu_id_counter++;

		DRUID::MenuItemPtr menuItem = sguiMenu->item(i);


		wxString labelWxStr(menuItem->key.c_str(), wxConvUTF8);
		wxString helpWxStr(menuItem->help.c_str(), wxConvUTF8);

		std::string itemKey = menuItemKeyToHotKey(menuItem->key, &hotKeys);
		wxMenuItem * mItem = new wxMenuItem(intoMenu, elementId,
				DRUID_STDSTRING_TOWX(itemKey), helpWxStr);

		wxButton * btn = new wxButton(buttonWindow, elementId, labelWxStr);
		btn->SetHelpText(helpWxStr);
		btn->SetForegroundColour(darkFg);
		btn->SetMinSize(btnMinSize);
		btn->SetMaxSize(btnMaxSize);

		wxBoxSizer * btnLabelSizer = new wxBoxSizer(wxHORIZONTAL);

		if (!i)
			btn->SetFocus();

		if (menuItem->type == DRUID::MenuItem_Command) {
			// connect to callbacks for commands

			btnLabelSizer->Add(new wxStaticBitmap(buttonWindow, wxID_ANY, cmd_icon),
					wxSizerFlags(0).Align(wxALIGN_CENTER));

			this->Connect(elementId, wxEVT_COMMAND_MENU_SELECTED,
					wxCommandEventHandler(MainWindow::OnExecuteMenuItem),
					new MenuItemClickUserData(sguiMenu, menuItem), this);

			btn->Connect(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,
					wxCommandEventHandler(MainWindow::OnRunCommand),
					new ButtonClickUserData(menuItem), this);

		} else if (menuItem->type == DRUID::MenuItem_Submenu) {
			btnLabelSizer->Add(new wxStaticBitmap(buttonWindow, elementId, submenu_icon),
					wxSizerFlags(0).Align(wxALIGN_CENTER));

			wxMenu * theSubMenu = new wxMenu(DRUID_STDSTRING_TOWX(menuItem->subMenu->name()));
			mItem->SetSubMenu(theSubMenu);

			btn->Connect(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED,
					wxCommandEventHandler(MainWindow::OnEnterSubMenu),
					new ButtonClickUserData(menuItem), this);


			buildDeviceMenu(menuItem->subMenu, theSubMenu);

		} else {
			// ??
		}

		btn->SetMinSize(wxSize(70, 35));

		btnLabelSizer->Add(btn,
						wxSizerFlags(1).Expand().Align(
								wxALIGN_CENTER));
		btnSizer->Add(btnLabelSizer, wxSizerFlags(1).Expand().Align(
				wxALIGN_CENTER));

		wxStaticText * helptxt = new wxStaticText(buttonWindow, wxID_ANY, helpWxStr);
		helptxt->Wrap(225);

		btnSizer->Add(helptxt,
				wxSizerFlags(3).Align(wxALIGN_CENTER_VERTICAL).Border(wxLEFT, 5));



		intoMenu->Append(mItem);
	}

	menuSizer->Add(btnSizer, wxSizerFlags(1).Border(wxALL & ~wxBottom, 5));

	buttonWindow->innerSizer()->Add(menuSizer, wxSizerFlags(1).Border(wxALL & ~wxBottom, 5));

}
Пример #2
0
int Application::readFile()
{
    char hstr[200]; //, msg[200];
    int cnt;
    DynZoneElement **curZone;
    DynZoneDescr *curDescr;

    rewind(fp);
    fpos = ftell(fp);
    line = 1;

    isused = new int[nVars];
    for (cnt = 0; cnt < nVars; cnt++)
        isused[cnt] = -1;
    for (nused = 0, cnt = 0; cnt < 6; cnt++)
        if (usedVars[cnt] != 0)
        {
            isused[usedVars[cnt] - 1] = nused;
            nused++;
        }

    data = new DynZoneElement[nused];
    for (cnt = 0; cnt < nused; cnt++)
    {
        data[cnt].next = NULL;
        data[cnt].prev = NULL;
        data[cnt].value = NULL;
    }
    curZone = new DynZoneElement *[nused];
    for (cnt = 0; cnt < nused; cnt++)
        curZone[cnt] = &data[cnt];
    zone = new DynZoneDescr;
    zone->next = NULL;
    zone->prev = NULL;
    curDescr = zone;

    while (fnextstring(&fpos, hstr))
    {
        if (strcmp(upStr(hstr), "TITLE") == 0)
        {
            fscanf(fp, "%*[^\n]");
        }
        else if (strcmp(upStr(hstr), "VARIABLES") == 0)
        {
            fscanf(fp, "%*[^\n]");
        }
        else if (strcmp(upStr(hstr), "ZONE") == 0)
        {
            if (!readZoneRecord(curZone, &curDescr))
            {
                delete[] curZone;
                return (FALSE);
            }
        }
        else if (strcmp(upStr(hstr), "TEXT") == 0)
        {
            // readTextRecord ();
        }
        else if (strcmp(upStr(hstr), "GEOMETRY") == 0)
        {
            // readGeometryRecord ();
        }
        else if (strcmp(upStr(hstr), "CUSTOMLABELS") == 0)
        {
            // readCustomLabelsRecord ();
        }
        else
        {
            // Fehler, falls ALLE Records von Routinen bedient werden
            // sprintf (msg, "unknown record type >>%s<<", hstr);
            // fileformaterror (msg);
            // return (FALSE);
        }
    }
    delete[] curZone; // geloescht werden nur Verweise, NICHT die Daten

    return (TRUE);
}
Пример #3
0
int Application::readZoneHeader(DynZoneDescr **curDescrP)
{
    char msg[200], hstr[200], LFtest[200];
    DynZoneDescr *curDescr;

    curDescr = *curDescrP;
    if (curDescr->prev == NULL)
        nZones = 0;
    // curDescr Element hinzufuegen
    curDescr->next = new DynZoneDescr;
    curDescr->next->prev = curDescr;
    curDescr = curDescr->next;
    *curDescrP = curDescr;
    curDescr->next = NULL;

    // curDescr initialisieren
    strcpy(curDescr->Title, "");
    strcpy(curDescr->Color, "");
    curDescr->Format = POINT;
    curDescr->ndup = 0;
    strcpy(curDescr->DataTypeList, "");
    curDescr->i = 0;
    curDescr->j = 1;
    curDescr->k = 1;
    curDescr->n = 0;
    curDescr->e = 0;
    curDescr->et = 0;
    curDescr->nv = 0;

    strcpy(LFtest, "");
    fscanf(fp, "%*[\x1-\x9\xb- ,]");
    fscanf(fp, "%[\n]", LFtest);
    while (strlen(LFtest) == 0)
    {
        fscanf(fp, "%[^\x1-\x9\xb- =]%*[ =]", hstr);
        if (strcmp(upStr(hstr), "T") == 0) // Zonentitel
            fscanf(fp, "%[^\"]\"%*[^\"]\"", curDescr->Title);
        else if (strcmp(upStr(hstr), "C") == 0) // Zonenfarbe
            fscanf(fp, "%[^\x1- ,]", curDescr->Color);
        else if (strcmp(upStr(hstr), "F") == 0) // Format
        {
            fscanf(fp, "%[^\x1- ,]", hstr);
            if (strcmp(upStr(hstr), "POINT") == 0)
                curDescr->Format = POINT;
            else if (strcmp(upStr(hstr), "BLOCK") == 0)
                curDescr->Format = BLOCK;
            else if (strcmp(upStr(hstr), "FEPOINT") == 0)
                curDescr->Format = FEPOINT;
            else if (strcmp(upStr(hstr), "FEBLOCK") == 0)
                curDescr->Format = FEBLOCK;
            else
            {
                sprintf(msg, "unknown zone format >>%s<<", hstr);
                fileformaterror(msg);
                return (FALSE);
            }
        }
        else if (strcmp(upStr(hstr), "D") == 0) // duplist
        {
            fscanf(fp, "%*[^(]");
            fscanf(fp, "(");
            for (curDescr->ndup = 0; fscanf(fp, "%[)]", hstr) == 0; curDescr->ndup++)
                if (fscanf(fp, "%i%*[ ,]", &(curDescr->duplist[curDescr->ndup])) != 1)
                {
                    fileformaterror("numeric value expected");
                    return (FALSE);
                }
            if ((nZones == 0) && (curDescr->ndup != 0))
            {
                fileformaterror("can't dup values in first zone record");
                return (FALSE);
            }
        }
        else if (strcmp(upStr(hstr), "DT") == 0) // datatypelist
            fscanf(fp, "%[^(](%*[^)])", curDescr->DataTypeList);
        else if (strcmp(upStr(hstr), "I") == 0) // fuer i,j,k-Daten
            fscanf(fp, "%i", &curDescr->i);
        else if (strcmp(upStr(hstr), "J") == 0)
            fscanf(fp, "%i", &curDescr->j);
        else if (strcmp(upStr(hstr), "K") == 0)
            fscanf(fp, "%i", &curDescr->k);
        else
            // numnodes, ab hier fuer FE-Zones
            if (strcmp(upStr(hstr), "N") == 0)
            fscanf(fp, "%i", &curDescr->n);
        else
            // numelement
            if (strcmp(upStr(hstr), "E") == 0)
            fscanf(fp, "%i", &curDescr->e);
        else
            // elementtype -> not yet
            if (strcmp(upStr(hstr), "ET") == 0)
            fscanf(fp, "%*[^\x1-\x9\xb- ,]");
        else
            // nodevariable -> not yet
            if (strcmp(upStr(hstr), "NV") == 0)
            fscanf(fp, "%*[^\"]\"%*[^\"]\"");

        fpos = ftell(fp);
        strcpy(LFtest, "");
        fscanf(fp, "%*[\x1-\x9\xb- ,]");
        fscanf(fp, "%[\n]", LFtest);
        if (feof(fp))
        {
            fileformaterror("unexpected EOF");
            return (FALSE);
        }
    }
    line += strlen(LFtest);
    if (curDescr->i == 0)
    {
        fileformaterror("i==0");
        return (FALSE);
    }
    return (TRUE);
}
Пример #4
0
int Application::readFileHeader(FILE *fp, char *Title, int *n, char **VarNames)
{
    char hstr[200], LFtest[200]; // Hilfs-String zum Einlesen
    long dummy;
    float f;

    (*n) = 0;
    strcpy(Title, "");

    rewind(fp);
    fpos = ftell(fp);
    line = 1;

    if (!fnextstring(&fpos, hstr))
    {
        fileformaterror("unexpected EOF");
        return (FALSE);
    }

    if (strcmp(upStr(hstr), "TITLE") == 0)
    {
        fscanf(fp, "%*[^\"]%*[\"]%[^\"]%*[^\n]", Title);
        if (!fnextstring(&fpos, hstr))
        {
            fileformaterror("unexpected EOF");
            return (FALSE);
        }
    }

    if (strcmp(upStr(hstr), "VARIABLES") == 0)
    {
        strcpy(LFtest, "");
        fscanf(fp, "%*[^\"\n]");
        fscanf(fp, "%[\n]", LFtest);
        for ((*n) = 0; strlen(LFtest) == 0; (*n)++)
        {
            fscanf(fp, "%*[\"]%[^\"\n]%[\n]", hstr, LFtest);
            if (strlen(LFtest) != 0)
            {
                fileformaterror("unexpected EOL (>\"< expected)");
                return (FALSE);
            }
            VarNames[(*n) + 1] = new char[strlen(hstr) + 1];
            strcpy(VarNames[(*n) + 1], hstr);
            fscanf(fp, "%*[\"]%*[^\"\n]");
            fscanf(fp, "%[\n]", LFtest);
        }
        if ((*n) == 0)
        {
            fileformaterror("incomplete variable definition");
            return (FALSE);
        }
    }
    else
    {
        fseek(fp, fpos, SEEK_SET);
        if (!fnextfloat(&fpos, &f))
        {
            fseek(fp, fpos, SEEK_SET);
            do
            {
                if (!fnextstring(&dummy, hstr))
                {
                    fileformaterror("unexpected EOF ('ZONE' expected)");
                    return (FALSE);
                }
            } while (strcmp(upStr(hstr), "ZONE") != 0);
            fscanf(fp, "%*[^\n]%*[\n]");
            line++;
        }
        else
            fseek(fp, fpos, SEEK_SET);

        fscanf(fp, "%*[\x1-\x9\xb- ]");
        for ((*n) = 0; fscanf(fp, "%[\n]", LFtest) == 0; (*n)++)
        {
            fscanf(fp, "%s%*[\x1-\x9\xb- ]", hstr);
            if (sscanf(hstr, "%f", &f) != 1)
            {
                fileformaterror("numeric value expected");
                return (FALSE);
            }
            VarNames[(*n) + 1] = new char[10];
            sprintf(VarNames[(*n) + 1], "v%i", (*n) + 1);
        }

        if ((*n) == 0)
        {
            fileformaterror("number of variables == 0");
            return (FALSE);
        }
    }
    return (TRUE);
}