/*
 * If a file is double-clicked, load it in a different thread to prevent locking the GUI
 */
void PlottingWidget::fileSelected(QListWidgetItem *item)
{
    tlbl->setText("Loading "+item->text());
    progBar->setVisible(true);
    progBar->setRange(0,0);
    progBar->setValue(0);

    LoadBigFile *loadFile = new LoadBigFile(item->text());

    connect(loadFile, SIGNAL(sendFileData(QVector<QVector<QPointF> >)), this, SLOT(initEcg(QVector<QVector<QPointF> >)));

    loadFile->start();

    //Read header file and display information about the recording
    QFileInfo fInfo(item->text());
    QFile headerFile(fInfo.baseName()+"_header.txt");
    if (headerFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream headerTextStream(&headerFile);
        QString headerText;

        while (!headerTextStream.atEnd()) {
            headerText += headerTextStream.readLine() + "\n";
        }

        headerTextArea->setText(headerText);
        headerTextStream.flush();
        headerFile.close();
    }
}
예제 #2
0
파일: unpackgob.cpp 프로젝트: adituv/regob
void unpackGob(std::string gobpath, std::string headerpath, std::string outputpath) {
	std::ifstream headerFile(headerpath, std::ifstream::binary);

	std::unique_ptr<GobHeader> header(GobHeader::FromStream(headerFile));
	headerFile.close();

	std::ifstream dataFile(gobpath, std::ifstream::binary);

	std::for_each(header->fileEntries.cbegin(), header->fileEntries.cend(), [&dataFile, &header, &outputpath](FileEntry file) {
		auto chunks = header->GetFileChunks(file);
		std::ostringstream filename;
		filename << outputpath << std::hex << std::setw(8) << std::setfill('0') << file.nameChecksum;
	
		std::ofstream outFile(filename.str(), std::ofstream::binary);

		std::for_each(chunks.cbegin(), chunks.cend(), [&dataFile, &outFile](ChunkHeader chunk) {
			std::vector<char> buf(chunk.chunkSize);
			
			dataFile.seekg(chunk.offset);
			dataFile.read(&buf[0], chunk.chunkSize);

			outFile << &buf[0];
		});

		outFile.close();
	});

	dataFile.close();
}
예제 #3
0
void TestDataFileMakerDlg::OnBnClickedCreate16Bit()
{
	CFileDialog dlg(FALSE, "16g", "test_16bit", OFN_OVERWRITEPROMPT, "16-bit Gray (*.16g)|*.16g|All Files (*.*)|*.*||");
	if (dlg.DoModal() != IDOK) return;

	CString path(dlg.GetPathName());

	CFile headerFile(path, CFile::modeCreate|CFile::modeWrite);
	CArchive hdr(&headerFile, CArchive::store);

	const WORD bytesPerVoxel = 2;
	const WORD arrayWidth = 128;
	const WORD arrayHeight = 64;
	const WORD arrayDepth = 32;		// aka number of slices
	const double voxelWidth = 1.0;
	const double voxelHeight = 1.0;
	const double voxelDepth = 2.0;	// aka slice thickness

	hdr << bytesPerVoxel;
	hdr << arrayWidth;
	hdr << arrayHeight;
	hdr << arrayDepth;
	hdr << voxelWidth;
	hdr << voxelHeight;
	hdr << voxelDepth;

	// 256-entry color table
	hdr << (int)256;
	for (int i=0; i<256; ++i)
	{
		hdr << (BYTE)i;
		hdr << (BYTE)i;
		hdr << (BYTE)i;
	}

	hdr.Close();
	headerFile.Close();

	CFile dataFile(path.Left(path.ReverseFind('.')) + ".dat", CFile::modeCreate|CFile::modeWrite);
	CArchive dat(&dataFile, CArchive::store);
	for (int slice=0; slice < arrayDepth; slice++)
	{
		for (int row=0; row < arrayHeight; row++)
		{
			for (int col=0; col < arrayWidth; col++)
			{
				WORD value = (col % 0xFF) << 8;
				// 16-bit data are stored in big-endian order
				dat << HIBYTE(value);
				dat << LOBYTE(value);
			}
		}
	}
	dat.Close();
	dataFile.Close();

	MessageBox(".dat and .16g files created", "Confirmation", MB_OK);
}
예제 #4
0
void TestDataFileMakerDlg::OnBnClickedCreate15Bit()
{
	CFileDialog dlg(FALSE, "15c", "test_rgb", OFN_OVERWRITEPROMPT, "15-bit RGB (*.15c)|*.15c|All Files (*.*)|*.*||");
	if (dlg.DoModal() != IDOK) return;

	CString path(dlg.GetPathName());

	CFile headerFile(path, CFile::modeCreate|CFile::modeWrite);
	CArchive hdr(&headerFile, CArchive::store);

	const WORD bytesPerVoxel = 2;
	const WORD arrayWidth = 128;
	const WORD arrayHeight = 64;
	const WORD arrayDepth = 32;		// aka number of slices
	const double voxelWidth = 1.0;
	const double voxelHeight = 1.0;
	const double voxelDepth = 2.0;	// aka slice thickness

	hdr << bytesPerVoxel;
	hdr << arrayWidth;
	hdr << arrayHeight;
	hdr << arrayDepth;
	hdr << voxelWidth;
	hdr << voxelHeight;
	hdr << voxelDepth;

	// no color table required, #colors = 0
	hdr << (int)0;

	hdr.Close();
	headerFile.Close();

	CFile dataFile(path.Left(path.ReverseFind('.')) + ".dat", CFile::modeCreate|CFile::modeWrite);
	CArchive dat(&dataFile, CArchive::store);
	for (int slice=0; slice < arrayDepth; slice++)
	{
		for (int row=0; row < arrayHeight; row++)
		{
			for (int col=0; col < arrayWidth; col++)
			{
				int r = col & 0x1F;
				int g = row & 0x1F;
				int b = 0x10;
				WORD rgb = (WORD)((r << 10) | (g << 5) | (b << 0));
				// 16-bit data are stored in big-endian order
				dat << HIBYTE(rgb);
				dat << LOBYTE(rgb);
			}
		}
	}
	dat.Close();
	dataFile.Close();

	MessageBox(".dat and .15c files created", "Confirmation", MB_OK);
}
예제 #5
0
    doim::CxxIncludeDirectorySet cxxIncludeDirectories(
        doim::CxxHeader::EVisibility visibility, const doim::FsDirectorySPtr& root) const
    {
        auto self = static_cast<const Subject*>(this);

        doim::CxxIncludeDirectorySet set;

        const auto& it = mHeaders.find(visibility);

        doim::FsDirectorySet directories;
        if (it != mHeaders.end())
            for (const auto& headerSet : it->second)
                directories.insert(headerSet.first);

        const auto& protobufs = self->protobufs();
        const auto& protobufIt = protobufs.find(visibility);
        if (protobufIt != protobufs.end())
            for (const auto& headerSet : protobufIt->second)
                directories.insert(headerSet.first);

        for (const auto& directory : directories)
        {
            FileOriginMap files;

            if (it != mHeaders.end())
            {
                const auto& fileSetIt = it->second.find(directory);
                if (fileSetIt != it->second.end())
                    for (const auto& file : fileSetIt->second)
                        files.insert({file, nullptr});
            }

            if (protobufIt != protobufs.end())
            {
                const auto& protobufFileSetIt = protobufIt->second.find(directory);
                if (protobufFileSetIt != protobufIt->second.end())
                    for (const auto& file : protobufFileSetIt->second)
                        files.insert({self->headerFile(file),
                                      doim::ProtobufFile::unique(directory, file)});
            }

            const auto& headers = cxxHeaders(visibility, root, files);

            set.insert(doim::CxxIncludeDirectory::unique(self->cxxIncludeDirectoryType(),
                                                         directory,
                                                         headers));
        }

        return set;
    }
예제 #6
0
void CCodeParser::ParseCFiles(wxString className)
{
    m_className = className;
    wxTextFile headerFile(m_hFile);
    wxTextFile sourceFile(m_cFile);

    wxString header;
    wxString source;

    //start opening files
    if (headerFile.Open())
    {
        wxString Str;

        Str = headerFile.GetFirstLine();
        while (!(headerFile.Eof()))
        {
            header << Str;
            header << wxT('\n');
            Str = headerFile.GetNextLine();
        }
        headerFile.Close();
    }
    else
    {
        header = wxT("");
    }
    if (sourceFile.Open())
    {
        wxString Str;

        source = sourceFile.GetFirstLine();
        while (!(sourceFile.Eof()))
        {
            source << Str;
            source << wxT('\n');
            Str = sourceFile.GetNextLine();
        }
        sourceFile.Close();
    }
    else
    {
        source = wxT("");
    }

    //parse the file contents
    ParseCCode(header, source);
}
예제 #7
0
Core::GeneratedFiles ModelClassWizard::generateFiles(
        const QWizard *w,QString *errorMessage) const
{
    Q_UNUSED(errorMessage);
    Core::GeneratedFiles ret;
    int pageId = w->property("_PageId_").toInt();
    ModelNamePage* page = qobject_cast<ModelNamePage*>(w->page(pageId));

    if(!page)
        return ret;
    ModelClassParameters params = page->parameters();
    QMap<QString,QString> replacementMap;

    replacementMap["{{UPPER_CLASS_NAME}}"] = params.className.toUpper();
    replacementMap["{{BASE_CLASS_NAME}}"] = params.baseClass;
    replacementMap["{{CLASS_NAME}}"] = params.className;
    replacementMap["{{CLASS_HEADER}}"] = QFileInfo(params.headerFile).fileName();

    Core::GeneratedFile headerFile(params.path + "/" + params.headerFile);
    headerFile.setEditorKind(CppEditor::Constants::CPPEDITOR_KIND);

    Core::GeneratedFile sourceFile(params.path + "/" + params.sourceFile);
    sourceFile.setEditorKind(CppEditor::Constants::CPPEDITOR_KIND);

    if(params.baseClass == "QAbstractItemModel")
    {
        headerFile.setContents(readFile(":/CustomProject/ItemModelHeader", replacementMap) );
        sourceFile.setContents(readFile(":/CustomProject/ItemModelSource", replacementMap) );
    }

    else if(params.baseClass == "QAbstractTableModel")
    {
        headerFile.setContents(readFile(":/CustomProject/TableModelHeader", replacementMap) );
        sourceFile.setContents(readFile(":/CustomProject/TableModelSource", replacementMap) );
    }

    else if(params.baseClass == "QAbstractListModel")
    {
        headerFile.setContents(readFile(":/CustomProject/ListModelHeader", replacementMap) );
        sourceFile.setContents(readFile(":/CustomProject/ListModelSource", replacementMap) );
    }

    ret << headerFile << sourceFile;
    return ret;
}
void D3D11InterfaceWriter::writeHeader(const string &outputHeader)
{
    ofstream headerFile(outputHeader);
    headerFile << endl << "class my" << name << " : public " << "I" << name << endl;
    headerFile << "{" << endl;
    headerFile << "public:" << endl;

    headerFile << "    I" << name << " *base;" << endl << endl;

    for (const D3D11InterfaceFunction &func : functions)
    {
        headerFile << "    ";
        headerFile << func.returnType << " ";
        headerFile << func.name << "(";
        headerFile << func.getParameterList();
        headerFile << ");" << endl;
    }
    headerFile << "};" << endl;
}
예제 #9
0
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
{
    const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
    const Designer::FormClassWizardParameters params = wizardDialog->parameters();

    if (params.uiTemplate().isEmpty()) {
        *errorMessage = QLatin1String("Internal error: FormClassWizard::generateFiles: empty template contents");
        return Core::GeneratedFiles();
    }

    // header
    const QString formFileName = buildFileName(params.path(), params.uiFile(), formSuffix());
    const QString headerFileName = buildFileName(params.path(), params.headerFile(), headerSuffix());
    const QString sourceFileName = buildFileName(params.path(), params.sourceFile(), sourceSuffix());

    Core::GeneratedFile headerFile(headerFileName);
    headerFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND));

    // Source
    Core::GeneratedFile sourceFile(sourceFileName);
    sourceFile.setEditorKind(QLatin1String(CppEditor::Constants::CPPEDITOR_KIND));

    // UI
    Core::GeneratedFile uiFile(formFileName);
    uiFile.setContents(params.uiTemplate());
    uiFile.setEditorKind(QLatin1String(Constants::C_FORMEDITOR));

    QString source, header;
    Designer::FormClassWizardGenerationParameters generationParameters;
    generationParameters.fromSettings(Core::ICore::instance()->settings());
    params.generateCpp(generationParameters, &header, &source);
    sourceFile.setContents(source);
    headerFile.setContents(header);

    if (Designer::Constants::Internal::debug)
        qDebug() << Q_FUNC_INFO << '\n' << header << '\n' << source;

    return  Core::GeneratedFiles() << headerFile << sourceFile << uiFile;
}
예제 #10
0
Core::GeneratedFiles FormClassWizard::generateFiles(const QWizard *w, QString *errorMessage) const
{
    const FormClassWizardDialog *wizardDialog = qobject_cast<const FormClassWizardDialog *>(w);
    const Designer::FormClassWizardParameters params = wizardDialog->parameters();

    if (params.uiTemplate.isEmpty()) {
        *errorMessage = QLatin1String("Internal error: FormClassWizard::generateFiles: empty template contents");
        return Core::GeneratedFiles();
    }

    // header
    const QString formFileName = buildFileName(params.path, params.uiFile, formSuffix());
    const QString headerFileName = buildFileName(params.path, params.headerFile, headerSuffix());
    const QString sourceFileName = buildFileName(params.path, params.sourceFile, sourceSuffix());

    Core::GeneratedFile headerFile(headerFileName);
    headerFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);

    // Source
    Core::GeneratedFile sourceFile(sourceFileName);
    sourceFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);

    // UI
    Core::GeneratedFile uiFile(formFileName);
    uiFile.setContents(params.uiTemplate);
    uiFile.setAttributes(Core::GeneratedFile::OpenEditorAttribute);

    QString source, header;

    QtDesignerFormClassCodeGenerator::generateCpp(params, &header, &source);
    sourceFile.setContents(source);
    headerFile.setContents(header);

    if (Designer::Constants::Internal::debug)
        qDebug() << Q_FUNC_INFO << '\n' << header << '\n' << source;

    return  Core::GeneratedFiles() << headerFile << sourceFile << uiFile;
}
GisRasterHdr::GisRasterHdr(const string& name)
{
    _status = false;
    GisAscFile headerFile(name);
    if(headerFile.good())
    {
        char charText[20];
        headerFile.getLine(charText, 20, ':');
        if(strcmp(charText, "proj") == 0)
        { //At least test first line!!!
            headerFile.getAscInt(_projId);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscInt(_zoneId);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscDouble(_north);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscDouble(_south);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscDouble(_east);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscDouble(_west);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscInt(_cols);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscInt(_rows);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscDouble(_ewresol);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscDouble(_nsresol);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscInt(_formatId);
            headerFile.getLine(charText, 20, ':');
            headerFile.getAscInt(_compressed);
            _status = true;
        }
    }
}
예제 #12
0
std::pair<std::string, std::string> ArduinoNNCompiler::getHeaderAndFooter() {
	#ifndef SOURCE_DIR
	    std::cerr << "SOURCE_DIR not properly specified from CMake."
	    		<< " Generating NeuralNetwork.h will not work."<< std::endl;
	#endif
	std::stringstream headerFileName;
	headerFileName << TOSTRING(SOURCE_DIR) << "/brain/NeuralNetwork.h";
	std::ifstream headerFile(headerFileName.str().c_str());
	std::string line;
	std::stringstream headerStream;
	std::stringstream footerStream;
	bool onFooter = false;
	while (std::getline(headerFile, line)) {
		if(line.find("HEADER_FOOTER_BREAK") != std::string::npos) {
			onFooter = true;
		} else if(onFooter) {
			footerStream << line << std::endl;
		} else {
			headerStream << line << std::endl;
		}

	}
	return std::make_pair(headerStream.str(), footerStream.str());
}
예제 #13
0
void wxFormBuilder::DoCreateWxFormBuilderProject(const wxFBItemInfo& data)
{
	// add new virtual folder to the selected virtual directory
	wxString formbuilderVD;
	formbuilderVD = data.virtualFolder.BeforeFirst(wxT(':'));

	m_mgr->CreateGroupFolder(formbuilderVD, wxT("formbuilder"));
	wxString templateFile(m_mgr->GetInstallDirectory() + wxT("/templates/formbuilder/"));     //todo,todo

	switch (data.kind) {
	default:
	case wxFBItemKind_Dialog:
		templateFile << wxT("DialogTemplate.fbp");
		break;
	case wxFBItemKind_Frame:
		templateFile << wxT("FrameTemplate.fbp");
		break;
	case wxFBItemKind_Panel:
		templateFile << wxT("PanelTemplate.fbp");
		break;
	case wxFBItemKind_Dialog_With_Buttons:
		templateFile << wxT("DialogTemplateWithButtons.fbp");
		break;
	}

	wxFileName tmplFile(templateFile);
	if (!tmplFile.FileExists()) {
		wxMessageBox(wxString::Format(wxT("Cant find wxFormBuilder template file '%s'"), tmplFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING);
		return;
	}

	// place the files under the VD's project owner
	wxString err_msg;
	wxString project = data.virtualFolder.BeforeFirst(wxT(':'));
	ProjectPtr proj = m_mgr->GetSolution()->FindProjectByName(project, err_msg);
	if (proj) {
		wxString files_path = proj->GetFileName().GetPath(wxPATH_GET_SEPARATOR|wxPATH_GET_VOLUME);
		// copy the file to here
		wxFileName fbpFile(files_path, data.file + wxT(".fbp"));
		if (!wxCopyFile(tmplFile.GetFullPath(), fbpFile.GetFullPath())) {
			wxMessageBox(wxString::Format(wxT("Failed to copy tempalte file to '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING);
			return;
		}
		// open the file, and replace expand its macros
		wxString content;
		if (!ReadFileWithConversion(fbpFile.GetFullPath().c_str(), content)) {
			wxMessageBox(wxString::Format(wxT("Failed to read file '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING);
			return;
		}

		content.Replace(wxT("$(BaseFileName)"), data.file);
		content.Replace(wxT("$(ProjectName)"), data.className);
		content.Replace(wxT("$(Title)"), data.title);
		content.Replace(wxT("$(ClassName)"), data.className);

		if (!WriteFileWithBackup(fbpFile.GetFullPath().c_str(), content, false)) {
			wxMessageBox(wxString::Format(wxT("Failed to write file '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING);
			return;
		}

		// add the file to the project
		wxArrayString paths;
		paths.Add(fbpFile.GetFullPath());
		m_mgr->AddFilesToGroupFolder(project + wxT(":formbuilder"), paths);

		// // first we launch wxFB with the -g flag set
		wxString genFileCmd;
		genFileCmd << GetWxFBPath() << wxT(" -g ") << fbpFile.GetFullPath();

		wxArrayString dummy, filesToAdd;
		ProcUtils::SafeExecuteCommand(genFileCmd, dummy);

		wxFileName cppFile(fbpFile.GetPath(), data.file + wxT(".cpp"));
		wxFileName headerFile(fbpFile.GetPath(), data.file + wxT(".h"));

		if (cppFile.FileExists()) {
			filesToAdd.Add(cppFile.GetFullPath());
		}

		if (headerFile.FileExists()) {
			filesToAdd.Add(headerFile.GetFullPath());
		}

		if (filesToAdd.GetCount()) {
			m_mgr->AddFilesToGroupFolder(data.virtualFolder, filesToAdd);
		}

		DoLaunchWxFB(fbpFile.GetFullPath());
	}
}
예제 #14
0
void UmlArtifact::generate()
{
    if (! managed) {
        managed = TRUE;

        if (stereotype() == "text") {
            generate_text();
            return;
        }
        else if (stereotype() != "source")
            return;

        package_of_generated_artifact = package();

        const WrapperStr hdef = cppHeader();
        QLOG_INFO() << "Read header as: " + hdef.operator QString();
        const WrapperStr srcdef = cppSource();

        if (hdef.isEmpty() && srcdef.isEmpty()) {
            if (verbose())
                UmlCom::trace(WrapperStr("<hr><font face=helvetica>artifact <i>")
                              + name() + "</i> has an empty C++ definition</font><br>");

            return;
        }

        const WrapperStr & name = UmlArtifact::name();
        UmlPackage * pack = package();
        WrapperStr h_path = pack->header_path(name);
        WrapperStr src_path = pack->source_path(name);
        WrapperStr nasp_start;
        WrapperStr nasp_end;
        const char * cnasp = pack->cppNamespace();
        WrapperStr nasp = ((cnasp[0] == ':') && (cnasp[1] == ':'))
                         ? cnasp + 2 : cnasp;

        if (!nasp.isEmpty()) {
            int index = 0;
            int index2;
            WrapperStr closed = "\n} // namespace ";

            while ((index2 = nasp.find(':', index)) != -1) {
                WrapperStr na = nasp.mid(index, index2 - index);

                nasp_start += WrapperStr("namespace ") + na + " {\n\n";
                closed += na;
                nasp_end = closed + "\n" + nasp_end;
                closed += "::";
                nasp.replace(index2, 2, "_");
                index = index2 + 1;
            }

            nasp_start += WrapperStr("namespace ") + nasp.mid(index) + " {\n\n";
            closed += nasp.mid(index);
            nasp_end = closed + "\n" + nasp_end;
        }
        else {
            WrapperStr s;

            if (!hdef.isEmpty())
                s = " in <i> " + h_path + "</i>";

            if (!srcdef.isEmpty()) {
                if (!hdef.isEmpty())
                    s += " and <i> " + src_path + "</i>";
                else
                    s = " in <i> " + src_path + "</i>";
            }

            UmlCom::message(name);

            if (verbose())
                UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ")
                              + name + "</i>" + s + "</font><br>");
            else
                set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ")
                                 + name + "</i>" + s + "</font><br>");
        }

        // get bodies if preserve
        const Q3PtrVector<UmlClass> & cls = associatedClasses();

        if (preserve())
            UmlOperation::read_bodies(h_path, src_path);

        // compute dependencies

        bool all_in_h = (hdef.find("${all_includes}") != -1);
        Q3PtrList<CppRefType> dependencies;
        unsigned n = cls.count();
        unsigned index;

        for (index = 0; index != n; index += 1)
            cls[index]->compute_dependencies(dependencies, all_in_h);

        // generate header file

        WrapperStr h_incl;
        WrapperStr src_incl;
        WrapperStr decl;
        bool incl_computed = FALSE;

        if (!hdef.isEmpty()) {


            //headerFile->append("Test DAta");

            QLOG_INFO() << "openign file for writing: ";
            //QTextStream f_h(file.data()); //[lgfreitas] Now QTextStream receives a pointer to a byte array...
            QSharedPointer<QByteArray> headerFile(new QByteArray());
            QTextStream f_h(headerFile.data(), QFile::WriteOnly);
            f_h.setCodec(QTextCodec::codecForLocale());
            //QTextStream f_h(headerFile.data(), QIODevice::WriteOnly);
            //QString h_copy = QString(hdef.operator QString());
            const char * p = hdef;
            const char * pp = 0;

            for (;;)
            {
                QLOG_INFO() << "At this point P is: " << QString(p);
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (*p == 0)
                        break;
                }


                if (*p == '@')
                    manage_alias(p, f_h);
                else if (*p != '$')
                {
                    QTextCodec* codec = QTextCodec::codecForLocale();
                    //f_h << codec->fromUnicode(*p,1);
                    //p++;
                    f_h << toLocale(p);
                }
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${name}", 7)) {
                    p += 7;
                    f_h << name;
                }
                else if (!strncmp(p, "${Name}", 7)) {
                    p += 7;
                    //QLOG_INFO() << "Outputting name: " << name;
                    f_h << capitalize(name);
                }
                else if (!strncmp(p, "${NAME}", 7)) {
                    p += 7;
                    f_h << name.upper();
                }
                else if (!strncmp(p, "${nAME}", 7)) {
                    p += 7;
                    f_h << name.lower();
                }
                else if (!strncmp(p, "${namespace}", 12)) {
                    p += 12;
                    f_h << nasp;
                }
                else if (!strncmp(p, "${NAMESPACE}", 12)) {
                    p += 12;
                    f_h << nasp.upper();
                }
                else if (!strncmp(p, "${includes}", 11)
                         || !strncmp(p, "${all_includes}", 15))
                {
                    QLOG_INFO() << "REaDING INCLUDES";
                    p += (p[2] == 'a') ? 15 : 11;
                    QLOG_INFO() << "Modified p 1 to be" << QString(p);
                    if (!incl_computed)
                    {
                        incl_computed = TRUE;
                        CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this);
                        QLOG_INFO() << "Modified hdef to be: " << hdef.operator QString();

                    }
                    QLOG_INFO() << "Modified p 2 to be" << QString(p);
                    if (!h_incl.isEmpty())
                    {
                        f_h << h_incl;

                        if (*p != '\n')
                            f_h << '\n';
                    }
                    else if (*p == '\n')
                        p += 1;
                    QLOG_INFO() << "FINISHED INCLUDES";
                }
                else if (!strncmp(p, "${declarations}", 15))
                {
                    p += 15;

                    if (!incl_computed)
                    {
                        incl_computed = TRUE;
                        CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this);
                    }
                    QLOG_INFO() << "DECLS IS: " << decl.operator QString();
                    if (!decl.isEmpty())
                    {
                        f_h << decl;

                        if (*p != '\n')
                            f_h << '\n';
                    }
                    else if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${namespace_start}", 18)) {
                    p += 18;

                    if (!nasp_start.isEmpty())
                        f_h << nasp_start;

                    if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${namespace_end}", 16)) {
                    p += 16;

                    if (!nasp_end.isEmpty())
                        f_h << nasp_end;

                    if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${definition}", 13)) {
                    p += 13;

                    for (index = 0; index != n; index += 1)
                        cls[index]->generate_decl(f_h, current_indent(p, hdef.operator QString()));

                    if (*p == '\n')
                        p += 1;
                }
                else
                    // strange
                    f_h << toLocale(p);
            }

            f_h << '\000';
            f_h.flush();

            if (must_be_saved(h_path, headerFile->data())) {
                QLOG_INFO() << "this is essentially what goes to the header file: " << headerFile->size();
                write_trace_header();

                //FILE * fp_h;
                 QFile file(h_path);
                if (!file.open(QFile::WriteOnly))
                {
                    UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ")
                                  + name + "</i> : cannot open <i> "
                                  + h_path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
                                  + pack->name() + "</i> C++ directory specification</b></font><br>");
                    incr_error();
                }
                else {
                    QLOG_INFO() << "this is essentially what goes to the file: " << headerFile->constData();

                    QTextCodec* codec = QTextCodec::codecForLocale();
                    QTextStream out(&file);
                    out.setCodec(QTextCodec::codecForLocale());
                    QString temp(*headerFile.data());
                    out << codec->toUnicode(temp);
                    //out << *headerFile.data();
                    out.flush();
                }
            }
            else {
                WrapperStr th = get_trace_header();

                if (th.isEmpty())
                    UmlCom::trace(WrapperStr("<br><font face=helvetica><i> ")
                                  + h_path + "</i> not modified</font><br>");
                else
                    set_trace_header(th + "<font face=helvetica><i> "
                                     + h_path + "</i> not modified</font><br>");
            }
        }

        // generate source file

        if (!srcdef.isEmpty()) {
            QSharedPointer<QByteArray> file(new QByteArray());
            QTextStream f_src(file.data(), QIODevice::WriteOnly);
            const char * p = srcdef;
            const char * pp = 0;

            for (;;) {
                if (*p == 0) {
                    if (pp == 0)
                        break;

                    // comment management done
                    p = pp;
                    pp = 0;

                    if (*p == 0)
                        break;
                }

                if (*p == '@')
                    manage_alias(p, f_src);
                else if (*p != '$')
                    f_src << toLocale(p);
                else if (!strncmp(p, "${comment}", 10))
                    manage_comment(p, pp, CppSettings::isGenerateJavadocStyleComment());
                else if (!strncmp(p, "${description}", 14))
                    manage_description(p, pp);
                else if (!strncmp(p, "${name}", 7)) {
                    // for file header
                    p += 7;
                    f_src << name;
                }
                else if (!strncmp(p, "${includes}", 11)) {
                    p += 11;

                    if (!incl_computed) {
                        incl_computed = TRUE;
                        CppRefType::compute(dependencies, hdef.operator QString(), srcdef, h_incl, decl, src_incl, this);
                    }

                    if (!src_incl.isEmpty()) {
                        f_src << src_incl;

                        if (*p != '\n')
                            f_src << '\n';
                    }
                    else if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${members}", 10)) {
                    p += 10;

                    for (index = 0; index != n; index += 1)
                        cls[index]->generate_def(f_src, current_indent(p, srcdef), FALSE);

                    if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${namespace_start}", 18)) {
                    p += 18;

                    if (!nasp_start.isEmpty())
                        f_src << nasp_start;

                    if (*p == '\n')
                        p += 1;
                }
                else if (!strncmp(p, "${namespace_end}", 16)) {
                    p += 16;

                    if (!nasp_end.isEmpty())
                        f_src << nasp_end;

                    if (*p == '\n')
                        p += 1;
                }
                else
                    // strange
                    f_src << toLocale(p);
            }

            f_src << '\000';
            f_src.flush();

            if (must_be_saved(src_path, file->data())) {
                write_trace_header();

                FILE * fp_src;

                if ((fp_src = fopen((const char *) src_path, "wb")) == 0) {
                    write_trace_header();
                    UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ")
                                  + name + " : </i> cannot open <i> "
                                  + src_path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
                                  + pack->name() + "</i> C++ directory specification</b></font><br>");
                    incr_error();
                }
                else {
                    fputs((const char *) file->data(), fp_src);
                    fclose(fp_src);
                }
            }
            else if (get_trace_header().isEmpty())
                UmlCom::trace(WrapperStr("<font face=helvetica><i> ")
                              + src_path + "</i> not modified</font><br>");
        }
    }
}
예제 #15
0
// FIXME: Put addProperty in PropertyAdder class and add endReadAhead function.
int addProperty(KCmdLineArgs *args)
{
    if(args->count() != 3)
    {
        std::cerr << "Usage: kode --add-property <class> <proprerty-type> "
                  << "<property-name>" << std::endl;
        return 1;
    }

    QString className = args->arg(0);
    QString type = args->arg(1);
    QString name = args->arg(2);

    kdDebug() << "Add property: class " << className << ": " << type << " " <<
              name << endl;

    QString headerFileName = className.lower() + ".h";

    QFile headerFile(headerFileName);
    if(!headerFile.open(IO_ReadOnly))
    {
        std::cerr << "Unable to open file '" << headerFileName.utf8() << "'" <<
                  std::endl;
        return 1;
    }

    QTextStream in(&headerFile);

    enum State { FindClass, FindConstructor, FindProperties, FindPrivate,
                 FindVariables, Finish
               };
    State state = FindClass;

    QString accessor;
    QString mutator;

    QString out;

    QString readAhead;

    QString line;
    while(!(line = in.readLine()).isNull())
    {
        //    std::cout << line.utf8() << std::endl;
        kdDebug() << state << " LINE: " << line << endl;
        QString readAheadPrevious = readAhead;
        readAhead += line + "\n";
        //    out += line + "\n";
        switch(state)
        {
            case FindClass:
                //        if ( line.find( QRegExp( className ) ) >= 0 ) {
                if(line.find(QRegExp("^\\s*class\\s+" + className)) >= 0)
                {
                    kdDebug() << "  FOUND CLASS" << endl;
                    state = FindConstructor;
                }
                break;
            case FindConstructor:
                if(line.find(QRegExp("^\\s*" + className + "\\s*\\(")) >= 0)
                {
                    kdDebug() << "  FOUND CONSTRUCTOR" << endl;
                    out += readAhead;
                    readAhead = QString::null;
                    state = FindProperties;
                }
                break;
            case FindProperties:
            {
                QRegExp re("(\\w+)\\s*\\(");
                if(re.search(line) >= 0)
                {
                    QString function = re.cap(1).lower();
                    if(!function.isEmpty())
                    {
                        kdDebug() << "Function: " << function << endl;
                        if(function == className || function == "~" + className)
                        {
                            out += readAhead;
                            readAhead = QString::null;
                        }
                        else
                        {
                            if(function.startsWith("set"))
                            {
                                mutator = function.mid(3);
                                kdDebug() << "MUTATOR: " << mutator << endl;
                            }
                            else
                            {
                                if(function == mutator)
                                {
                                    accessor = function;
                                    kdDebug() << "ACCESSOR: " << accessor << endl;
                                    out += readAhead;
                                    readAhead = QString::null;
                                }
                                else
                                {
                                    kdDebug() << "CREATE PROPERTY" << endl;
                                    out += readAheadPrevious;
                                    addPropertyFunctions(out, type, name);
                                    out += "\n";
                                    readAhead = line + "\n";
                                    state = FindPrivate;
                                }
                            }
                        }
                    }
                }
                else if(line.find(QRegExp("\\s*protected")) >= 0)
                {
                    state = FindPrivate;
                }
                else if(line.find(QRegExp("\\s*private")) >= 0)
                {
                    if(accessor.isEmpty())
                    {
                        addPropertyFunctions(out, type, name);
                        out += readAhead;
                        readAhead = QString::null;
                        addPropertyVariable(out, type, name);
                        state = Finish;
                    }
                    else
                    {
                        if(accessor == mutator)
                        {
                            out += readAheadPrevious;
                            addPropertyFunctions(out, type, name);
                            out += "\n";
                            out += line + "\n";
                            readAhead = QString::null;
                        }
                        state = FindVariables;
                    }
                }
            }
            break;
            case FindPrivate:
                if(line.find(QRegExp("\\s*private")) >= 0)
                {
                    if(accessor.isEmpty())
                    {
                        out += readAhead;
                        readAhead = QString::null;
                        addPropertyVariable(out, type, name);
                        state = Finish;
                    }
                    else
                    {
                        state = FindVariables;
                    }
                }
                break;
            case FindVariables:
            {
                if(line.find("m" + accessor.lower(), 0, false) >= 0)
                {
                    out += readAhead;
                    readAhead = QString::null;
                    addPropertyVariable(out, type, name);
                    state = Finish;
                }
            }
            break;
            case Finish:
                break;
        }
    }

    headerFile.close();

    out += readAhead;

    if(args->isSet("inplace"))
    {
        QString headerFileNameOut = headerFileName + ".kodeorig" ;

        KProcess proc;
        proc << "cp" << QFile::encodeName(headerFileName) <<
             QFile::encodeName(headerFileNameOut);

        if(!proc.start(KProcess::Block))
        {
            kdError() << "Copy failed" << endl;
        }
        else
        {
            kdDebug() << "Write to original file." << endl;
            if(!headerFile.open(IO_WriteOnly))
            {
                kdError() << "Unable to open file '" << headerFileName <<
                          "' for writing." << endl;
                return 1;
            }
            QTextStream o(&headerFile);
            o << out << endl;
        }
    }
    else
    {
        std::cout << out.utf8() << std::endl;
    }

    return 0;
}
예제 #16
0
//! [3]
void ClassWizard::accept()
//! [3] //! [4]
{
    QByteArray className = field("className").toByteArray();
    QByteArray baseClass = field("baseClass").toByteArray();
    QByteArray macroName = field("macroName").toByteArray();
    QByteArray baseInclude = field("baseInclude").toByteArray();

    QString outputDir = field("outputDir").toString();
    QString header = field("header").toString();
    QString implementation = field("implementation").toString();
//! [4]

    QByteArray block;

    if (field("comment").toBool()) {
        block += "/*\n";
        block += "    " + header.toAscii() + "\n";
        block += "*/\n";
        block += "\n";
    }
    if (field("protect").toBool()) {
        block += "#ifndef " + macroName + "\n";
        block += "#define " + macroName + "\n";
        block += "\n";
    }
    if (field("includeBase").toBool()) {
        block += "#include " + baseInclude + "\n";
        block += "\n";
    }

    block += "class " + className;
    if (!baseClass.isEmpty())
        block += " : public " + baseClass;
    block += "\n";
    block += "{\n";

    /* qmake ignore Q_OBJECT */

    if (field("qobjectMacro").toBool()) {
        block += "    Q_OBJECT\n";
        block += "\n";
    }
    block += "public:\n";

    if (field("qobjectCtor").toBool()) {
        block += "    " + className + "(QObject *parent = 0);\n";
    } else if (field("qwidgetCtor").toBool()) {
        block += "    " + className + "(QWidget *parent = 0);\n";
    } else if (field("defaultCtor").toBool()) {
        block += "    " + className + "();\n";
        if (field("copyCtor").toBool()) {
            block += "    " + className + "(const " + className + " &other);\n";
            block += "\n";
            block += "    " + className + " &operator=" + "(const " + className
                     + " &other);\n";
        }
    }
    block += "};\n";

    if (field("protect").toBool()) {
        block += "\n";
        block += "#endif\n";
    }

    QFile headerFile(outputDir + "/" + header);
    if (!headerFile.open(QFile::WriteOnly | QFile::Text)) {
        QMessageBox::warning(0, QObject::tr("Simple Wizard"),
                             QObject::tr("Cannot write file %1:\n%2")
                             .arg(headerFile.fileName())
                             .arg(headerFile.errorString()));
        return;
    }
    headerFile.write(block);

    block.clear();

    if (field("comment").toBool()) {
        block += "/*\n";
        block += "    " + implementation.toAscii() + "\n";
        block += "*/\n";
        block += "\n";
    }
    block += "#include \"" + header.toAscii() + "\"\n";
    block += "\n";

    if (field("qobjectCtor").toBool()) {
        block += className + "::" + className + "(QObject *parent)\n";
        block += "    : " + baseClass + "(parent)\n";
        block += "{\n";
        block += "}\n";
    } else if (field("qwidgetCtor").toBool()) {
        block += className + "::" + className + "(QWidget *parent)\n";
        block += "    : " + baseClass + "(parent)\n";
        block += "{\n";
        block += "}\n";
    } else if (field("defaultCtor").toBool()) {
        block += className + "::" + className + "()\n";
        block += "{\n";
        block += "    // missing code\n";
        block += "}\n";

        if (field("copyCtor").toBool()) {
            block += "\n";
            block += className + "::" + className + "(const " + className
                     + " &other)\n";
            block += "{\n";
            block += "    *this = other;\n";
            block += "}\n";
            block += "\n";
            block += className + " &" + className + "::operator=(const "
                     + className + " &other)\n";
            block += "{\n";
            if (!baseClass.isEmpty())
                block += "    " + baseClass + "::operator=(other);\n";
            block += "    // missing code\n";
            block += "    return *this;\n";
            block += "}\n";
        }
    }

    QFile implementationFile(outputDir + "/" + implementation);
    if (!implementationFile.open(QFile::WriteOnly | QFile::Text)) {
        QMessageBox::warning(0, QObject::tr("Simple Wizard"),
                             QObject::tr("Cannot write file %1:\n%2")
                             .arg(implementationFile.fileName())
                             .arg(implementationFile.errorString()));
        return;
    }
    implementationFile.write(block);

//! [5]
    QDialog::accept();
//! [5] //! [6]
}
예제 #17
0
ZLauncherFrame::ZLauncherFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	wxImage::SetDefaultLoadFlags(wxImage::GetDefaultLoadFlags() & ~wxImage::Load_Verbose);

	this->SetSizeHints( wxSize( 500,300 ), wxDefaultSize );
	this->SetBackgroundColour( APPLICATION_BACKGROUND );
	
	// GridBagSizer for the whole frame
	wxGridBagSizer* gridBagSizerFrame;
	gridBagSizerFrame = new wxGridBagSizer( 0, 0 );
	gridBagSizerFrame->SetFlexibleDirection( wxBOTH );
	gridBagSizerFrame->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	gridBagSizerFrame->SetMinSize( wxSize( 800,600 ) ); 

	// GridBagSizer For the "Body"  (HTML Window, etc.)
	wxGridBagSizer* gridBagSizerBody;
	gridBagSizerBody = new wxGridBagSizer( 0, 0 );
	gridBagSizerBody->SetFlexibleDirection( wxBOTH );
	gridBagSizerBody->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	
	// HTML Viewer
	m_htmlWin = wxWebView::New(this, wxID_ANY, wxWebViewDefaultURLStr, wxDefaultPosition, wxDefaultSize, wxWebViewBackendDefault, wxSIMPLE_BORDER);
	m_htmlWin->SetMinSize( wxSize( 400,300 ) );
	gridBagSizerBody->Add( m_htmlWin, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxALL|wxEXPAND, 5 );

	// GridBagSizer for the right side of the window
	wxGridBagSizer* gridBagSizerRight;
	gridBagSizerRight = new wxGridBagSizer( 0, 0 );
	gridBagSizerRight->SetFlexibleDirection( wxBOTH );
	gridBagSizerRight->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );

	// Add a spacer, for empty space, at the left side of the close button
	gridBagSizerRight->Add( 0, 0, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxEXPAND, 5 );

	// Close Button (Top Right)
	m_CloseButtonImg_Normal.LoadFile(GetResourcesDirectory() + CLOSE_BUTTON_NORMAL, wxBITMAP_TYPE_PNG);
	m_CloseButtonImg_Disabled.LoadFile(GetResourcesDirectory() + CLOSE_BUTTON_DISABLED, wxBITMAP_TYPE_PNG);
	m_CloseButtonImg_Pressed.LoadFile(GetResourcesDirectory() + CLOSE_BUTTON_PRESSED, wxBITMAP_TYPE_PNG);
	m_CloseButtonImg_Focus.LoadFile(GetResourcesDirectory() + CLOSE_BUTTON_FOCUS, wxBITMAP_TYPE_PNG);
	m_CloseButtonImg_Hover.LoadFile(GetResourcesDirectory() + CLOSE_BUTTON_HOVER, wxBITMAP_TYPE_PNG);
	m_btnClose = new wxButton(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT | wxBU_NOTEXT);
	m_btnClose->SetBitmap(m_CloseButtonImg_Normal);
	m_btnClose->SetBitmapDisabled(m_CloseButtonImg_Disabled);
	m_btnClose->SetBitmapPressed(m_CloseButtonImg_Pressed);
	m_btnClose->SetBitmapFocus(m_CloseButtonImg_Focus);
	m_btnClose->SetBitmapCurrent(m_CloseButtonImg_Hover);
	m_btnClose->SetBackgroundColour(APPLICATION_BACKGROUND);
	m_btnClose->Enable(true);

	gridBagSizerRight->Add( m_btnClose, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxALL, 5 );
	gridBagSizerRight->AddGrowableCol( 0 );
	gridBagSizerRight->AddGrowableRow( 0 );

	gridBagSizerBody->Add( gridBagSizerRight, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxALIGN_RIGHT|wxEXPAND, 5 );
	gridBagSizerBody->AddGrowableCol( 1 );
	gridBagSizerBody->AddGrowableRow( 0 );
	
	gridBagSizerFrame->Add( gridBagSizerBody, wxGBPosition( 0, 0 ), wxGBSpan( 1, 2 ), wxEXPAND, 5 );
	
	// Footer Area (Progress Bar and Launch button)
	wxGridBagSizer* gridBagSizerFooter;
	gridBagSizerFooter = new wxGridBagSizer( 0, 0 );
	gridBagSizerFooter->SetFlexibleDirection( wxBOTH );
	gridBagSizerFooter->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	
	// Text for the Progress Bar
	m_txtProgress = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxNO_BORDER );
	m_txtProgress->SetForegroundColour( COMPONENT_TEXT_COLOR );
	m_txtProgress->SetBackgroundColour( APPLICATION_BACKGROUND );
	
	gridBagSizerFooter->Add( m_txtProgress, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxALIGN_BOTTOM|wxEXPAND, 5 );

	// Progress Bar
	m_progress = new wxGauge( this, wxID_ANY, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL );
	m_progress->SetValue( 0 );
	m_progress->SetMinSize( wxSize( 500,25 ) );
	
	gridBagSizerFooter->Add( m_progress, wxGBPosition( 1, 0 ), wxGBSpan( 1, 1 ), wxALIGN_TOP|wxALL|wxEXPAND, 5 );
	gridBagSizerFooter->AddGrowableCol( 0 );
	gridBagSizerFooter->AddGrowableRow( 0 );
	
	gridBagSizerFrame->Add( gridBagSizerFooter, wxGBPosition( 1, 0 ), wxGBSpan( 1, 1 ), wxEXPAND, 5 );
	
	// Launch Button
	m_LaunchButtonImg_Normal.LoadFile(GetResourcesDirectory() + LAUNCH_BUTTON_NORMAL, wxBITMAP_TYPE_PNG);
	m_LaunchButtonImg_Disabled.LoadFile(GetResourcesDirectory() + LAUNCH_BUTTON_DISABLED, wxBITMAP_TYPE_PNG);
	m_LaunchButtonImg_Pressed.LoadFile(GetResourcesDirectory() + LAUNCH_BUTTON_PRESSED, wxBITMAP_TYPE_PNG);
	m_LaunchButtonImg_Focus.LoadFile(GetResourcesDirectory() + LAUNCH_BUTTON_FOCUS, wxBITMAP_TYPE_PNG);
	m_LaunchButtonImg_Hover.LoadFile(GetResourcesDirectory() + LAUNCH_BUTTON_HOVER, wxBITMAP_TYPE_PNG);
	m_btnLaunch = new wxButton( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxBU_EXACTFIT | wxBU_NOTEXT);
	m_btnLaunch->SetBitmap(m_LaunchButtonImg_Normal);
	m_btnLaunch->SetBitmapDisabled(m_LaunchButtonImg_Disabled);
	m_btnLaunch->SetBitmapPressed(m_LaunchButtonImg_Pressed);
	m_btnLaunch->SetBitmapFocus(m_LaunchButtonImg_Focus);
	m_btnLaunch->SetBitmapCurrent(m_LaunchButtonImg_Hover);
	m_btnLaunch->SetBackgroundColour(APPLICATION_BACKGROUND);
	m_btnLaunch->Enable( false );

	gridBagSizerFrame->Add( m_btnLaunch, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxALIGN_BOTTOM|wxALL, 5 );
	gridBagSizerFrame->AddGrowableCol( 0 );
	gridBagSizerFrame->AddGrowableRow( 0 );
	
	this->SetSizer( gridBagSizerFrame );
	this->Layout();

	this->Centre( wxBOTH );

	// Set background image, if any.
	SetBackgroundStyle(wxBG_STYLE_PAINT);
	if (g_BackgroundImage != wxEmptyString)
		m_backgroundImg.LoadFile(g_BackgroundImage, wxBITMAP_TYPE_PNG);


	// Bind Message Events
	Bind(wxEVT_PAINT, &ZLauncherFrame::PaintEvent, this);

	Bind(wxEVT_COMMAND_UPDATE_PROGRESS_BAR, &ZLauncherFrame::OnProgressBarUpdate, this);
	Bind(wxEVT_COMMAND_UPDATE_PROGRESS_TEXT, &ZLauncherFrame::OnProgressTextUpdate, this);

	Bind(wxEVT_COMMAND_HTML_SET_CONTENT, &ZLauncherFrame::OnHTMLSetContent, this);
	Bind(wxEVT_COMMAND_HTML_LOAD_PAGE, &ZLauncherFrame::OnHTMLLoadPage, this);

	Bind(wxEVT_COMMAND_ENABLE_LAUNCH_BUTTON, &ZLauncherFrame::OnEnableLaunchButton, this);

	Bind(wxEVT_CLOSE_WINDOW, &ZLauncherFrame::OnClose, this);

	Bind(wxEVT_WEBVIEW_NAVIGATING, &ZLauncherFrame::OnClickLink, this);

	// Bind Button Events
	m_btnClose->Bind(wxEVT_BUTTON, &ZLauncherFrame::OnCloseButtonClicked, this);
	m_btnLaunch->Bind(wxEVT_BUTTON, &ZLauncherFrame::OnLaunchButtonClicked, this);

	// Read Header html data from external file
	if (wxFile::Exists(GetResourcesDirectory() + g_PatchHTMLHeaderFileName))
	{
		wxFile headerFile(GetResourcesDirectory() + g_PatchHTMLHeaderFileName, wxFile::OpenMode::read);
		headerFile.ReadAll(&PatchHTMLHeader);
	}
	else
	{
		wxMessageBox(wxString::Format("HTML Header file missing. Make sure it can be found in the following directory:\n %s", GetResourcesDirectory() + g_PatchHTMLHeaderFileName), "Missing file", wxOK| wxICON_EXCLAMATION);
	}
}
예제 #18
0
void UmlArtifact::generate()
{
    if (! managed) {
        managed = TRUE;

        if (stereotype() == "text") {
            generate_text();
            return;
        }
        else if (stereotype() != "source")
            return;

        package_of_generated_artifact = package();
        current = this;

        const WrapperStr filedef = javaSource();

        if (filedef.isEmpty())
            return;

        const WrapperStr & name = this->name();
        WrapperStr path = package_of_generated_artifact->file_path(name);

        UmlCom::message(name);

        if (verbose())
            UmlCom::trace(WrapperStr("<hr><font face=helvetica>Generate code for <i> ")
                          + name + "</i> in " + path + "</i></font><br>");
        else
            set_trace_header(WrapperStr("<font face=helvetica>Generate code for <i> ")
                             + name + "</i> in " + path + "</i></font><br>");

        // get bodies if preserve
        const QVector<UmlClass*> & cls = associatedClasses();

        if (preserve())
            UmlOperation::read_bodies(path);

        // generate file

        unsigned n = cls.count();
        unsigned index;
        WrapperStr incl;
        QSharedPointer<QByteArray> headerFile(new QByteArray());
        QTextStream f(headerFile.data(), QIODevice::WriteOnly);
        const char * p = filedef;
        const char * pp = 0;

        for (;;) {
            if (*p == 0) {
                if (pp == 0)
                    break;

                // comment management done
                p = pp;
                pp = 0;

                if (*p == 0)
                    break;
            }

            if (*p == '@')
                manage_alias(p, f);
            else if (*p != '$')
                f << *p++;
            else if (!strncmp(p, "${comment}", 10))
                manage_comment(p, pp, JavaSettings::isGenerateJavadocStyleComment());
            else if (!strncmp(p, "${description}", 14))
                manage_description(p, pp);
            else if (!strncmp(p, "${name}", 7)) {
                p += 7;
                f << name;
            }
            else if (!strncmp(p, "${Name}", 7)) {
                p += 7;
                f << capitalize(name);
            }
            else if (!strncmp(p, "${NAME}", 7)) {
                p += 7;
                f << name.upper();
            }
            else if (!strncmp(p, "${nAME}", 7)) {
                p += 7;
                f << name.lower();
            }
            else if (!strncmp(p, "${imports}", 10)) {
                WrapperStr indent = current_indent(p, filedef);

                for (index = 0; index != n; index += 1)
                    cls[index]->generate_import(f, indent);

                p += 10;

                if (*p == '\n')
                    p += 1;
            }
            else if (!strncmp(p, "${package}", 10)) {
                p += 10;

                const WrapperStr & package = package_of_generated_artifact->javaPackage();

                if (!package.isEmpty())
                    f << "package " << package << ";\n\n";

                if (*p == '\n')
                    p += 1;
            }
            else if (!strncmp(p, "${definition}", 13)) {
                WrapperStr indent = current_indent(p, filedef);

                for (index = 0; index != n; index += 1)
                    cls[index]->generate(f, indent);

                p += 13;

                if (*p == '\n')
                    p += 1;
            }
            else
                // strange
                f << *p++;
        }

        f << '\000';
        f.flush();

        if (must_be_saved(path, headerFile->data())) {
            write_trace_header();

            FILE * fp;

            if ((fp = fopen((const char *) path, "wb")) == 0) {
                write_trace_header();
                UmlCom::trace(WrapperStr("<font color=\"red\"><b><i> ")
                              + name + "</i> : cannot open <i> "
                              + path + "</i>, edit the <i> generation settings</i> (tab directory) or the <i>"
                              + package_of_generated_artifact->name()
                              + "</i> Java directory specification</b></font><br>");
                incr_error();
            }
            else {
                fputs((const char *) headerFile->data(), fp);
                fclose(fp);
            }
        }
        else if (get_trace_header().isEmpty())
            UmlCom::trace(WrapperStr("<font face=helvetica><i> ")
                          + path + "</i> not modified</font><br>");

        if (imports != 0) {
            delete imports;
            imports = 0;
        }
    }
}
예제 #19
0
void WizardsPlugin::DoCreateNewPlugin()
{
    //Load the wizard
    PluginWizard wiz(wxTheApp->GetTopWindow());
    NewPluginData data;
    if (wiz.Run(data)) {
        //load the template file and replace all variables with the
        //actual values provided by user
        wxString filename(m_mgr->GetStartupDirectory() + wxT("/templates/gizmos/liteeditor-plugin.project.wizard"));
        wxString content;
        if (!ReadFileWithConversion(filename, content)) {
            return;
        }
        
        // Convert the paths provided by user to relative paths
        wxFileName fn(data.GetCodelitePath(), "");
        if ( !fn.MakeRelativeTo( wxFileName(data.GetProjectPath()).GetPath()) ) {
            wxLogMessage(wxT("Warning: Failed to convert paths to relative path."));
        }

#ifdef __WXMSW__
        wxString dllExt(wxT("dll"));
#else
        wxString dllExt(wxT("so"));
#endif

        wxString clpath = fn.GetFullPath();
        fn.Normalize(); // Remove all .. and . from the path
        
        if ( clpath.EndsWith("/") || clpath.EndsWith("\\") ) {
            clpath.RemoveLast();
        }
        
        content.Replace(wxT("$(CodeLitePath)"), clpath);
        content.Replace(wxT("$(DllExt)"), dllExt);
        content.Replace(wxT("$(PluginName)"), data.GetPluginName());
        wxString baseFileName = data.GetPluginName();
        baseFileName.MakeLower();
        content.Replace(wxT("$(BaseFileName)"), baseFileName);
        content.Replace(wxT("$(ProjectName)"), data.GetPluginName());

        //save the file to the disk
        wxString projectFileName;
        projectFileName << data.GetProjectPath();
        {
            wxLogNull noLog;
            ::wxMkdir( wxFileName(data.GetProjectPath()).GetPath() );
        }
        wxFFile file;
        if (!file.Open(projectFileName, wxT("w+b"))) {
            return;
        }

        file.Write(content);
        file.Close();

        //Create the plugin source and header files
        wxFileName srcFile(wxFileName(data.GetProjectPath()).GetPath(), baseFileName);
        srcFile.SetExt("cpp");
        
        wxFileName headerFile(wxFileName(data.GetProjectPath()).GetPath(), baseFileName);
        headerFile.SetExt("h");

        //---------------------------------------------------------------
        //write the content of the file based on the file template
        //---------------------------------------------------------------

        //Generate the source files
        filename = m_mgr->GetStartupDirectory() + wxT("/templates/gizmos/plugin.cpp.wizard");
        content.Clear();
        if (!ReadFileWithConversion(filename, content)) {
            wxMessageBox(_("Failed to load wizard's file 'plugin.cpp.wizard'"), _("CodeLite"), wxICON_WARNING | wxOK);
            return;
        }

        // Expand macros
        content.Replace(wxT("$(PluginName)"), data.GetPluginName());
        content.Replace(wxT("$(BaseFileName)"), baseFileName);
        content.Replace(wxT("$(PluginShortName)"), data.GetPluginName());
        content.Replace(wxT("$(PluginLongName)"), data.GetPluginDescription());
        content.Replace(wxT("$(UserName)"), wxGetUserName().c_str());
        
        // Notify the formatter plugin to format the plugin source files
        clSourceFormatEvent evtFormat(wxEVT_FORMAT_STRING);
        evtFormat.SetInputString( content );
        EventNotifier::Get()->ProcessEvent( evtFormat );
        content = evtFormat.GetFormattedString();
        
        // Write it down
        file.Open(srcFile.GetFullPath(), wxT("w+b"));
        file.Write(content);
        file.Close();
        
        //create the header file
        filename = m_mgr->GetStartupDirectory() + wxT("/templates/gizmos/plugin.h.wizard");
        content.Clear();
        if (!ReadFileWithConversion(filename, content)) {
            wxMessageBox(_("Failed to load wizard's file 'plugin.h.wizard'"), _("CodeLite"), wxICON_WARNING | wxOK);
            return;
        }

        // Expand macros
        content.Replace(wxT("$(PluginName)"), data.GetPluginName());
        content.Replace(wxT("$(BaseFileName)"), baseFileName);
        content.Replace(wxT("$(PluginShortName)"), data.GetPluginName());
        content.Replace(wxT("$(PluginLongName)"), data.GetPluginDescription());
        content.Replace(wxT("$(UserName)"), wxGetUserName().c_str());

        // format the content
        evtFormat.SetString(content);
        EventNotifier::Get()->ProcessEvent( evtFormat );
        content = evtFormat.GetString();
        
        // Write it down
        file.Open(headerFile.GetFullPath(), wxT("w+b"));
        file.Write(content);
        file.Close();

        //add the new project to the workspace
        wxString errMsg;

        //convert the path to be full path as required by the
        //workspace manager
        m_mgr->AddProject(projectFileName);
    }
}