void UmlPackage::reverse_main(const Q3CString & type, Q3CString comment) { // do not lost main ! Lex::mark(); UmlOperation::skip_body(); UmlArtifact * cp; #ifdef ROUNDTRIP bool roundtrip = FALSE; if ((cp = UmlArtifact::get_main()) != 0) { roundtrip = TRUE; cp->set_usefull(); } else #endif if ((cp = UmlBaseArtifact::create(get_deploymentview(0), "main")) == 0) { UmlCom::trace("<font face=helvetica><b>cannot create <i>artifact main</i></b></font><br><hr>"); return; } if (! comment.isEmpty()) { unsigned start = 0; do { comment.insert(start, "//"); start = comment.find('\n', start + 2) + 1; } while (start != 0); comment.append("\n\n"); } comment.append(type); comment.append(" main("); comment.append(Lex::region()); comment.append("\n"); #ifdef ROUNDTRIP if (roundtrip) { if (cp->cppSource() != comment) cp->set_CppSource(comment); return; } #endif cp->set_Stereotype("source"); cp->set_CppSource(comment); cp->set_CppHeader(0); }
void UmlArtifact::gen_app(const Q3CString & path) { Q3CString target; Q3CString pro; propertyValue("genpro target", target); propertyValue("genpro pro", pro); if (target.isEmpty()) { if ((target = name()) == "executable") target = UmlPackage::getProject()->name(); #ifdef WIN32 target += ".exe"; #endif } if (pro.isEmpty()) { pro = target; #ifdef WIN32 if (pro.right(4) == ".exe") pro.resize(pro.length() - 4); #endif QDir d(path); pro = d.absFilePath(pro + ".pro"); } Q3CString tmplt; Q3CString config; Q3CString defines; Q3CString includepath; Q3CString dependpath; Q3CString objectsdir; Q3CString footer; if (!propertyValue("genpro tmplt", tmplt)) tmplt = "app"; if (!propertyValue("genpro config", config)) config = "debug warn_on qt"; if (!propertyValue("genpro defines", defines)) defines = "WITHCPP WITHJAVA WITHPHP WITHPYTHON WITHIDL"; else if (defines.find("WITHPHP") == -1) { int n = 0; if (defines.find("WITHCPP") != -1) n += 1; if (defines.find("WITHJAVA") != -1) n += 1; if (defines.find("WITHIDL") != -1) n += 1; if (n > 1) defines += " WITHPHP WITHPYTHON"; } else if (defines.find("WITHPYTHON") == -1) { int n = 0; if (defines.find("WITHCPP") != -1) n += 1; if (defines.find("WITHJAVA") != -1) n += 1; if (defines.find("WITHIDL") != -1) n += 1; if (defines.find("WITHPHP") != -1) n += 1; if (n > 1) defines += " WITHPYTHON"; } propertyValue("genpro includepath", includepath); propertyValue("genpro dependpath", dependpath); propertyValue("genpro objectsdir", objectsdir); propertyValue("genpro footer", footer); for (;;) { Dialog dialog(this, path, pro, target, tmplt, config, defines, includepath, dependpath, objectsdir, footer); if (dialog.exec() != QDialog::Accepted) return; set_PropertyValue("genpro pro", pro); set_PropertyValue("genpro path", path); set_PropertyValue("genpro target", target); set_PropertyValue("genpro tmplt", tmplt); set_PropertyValue("genpro config", config); set_PropertyValue("genpro defines", defines); set_PropertyValue("genpro includepath", includepath); set_PropertyValue("genpro dependpath", dependpath); set_PropertyValue("genpro objectsdir", objectsdir); set_PropertyValue("genpro footer", footer); QFile f(pro); if (! f.open(QIODevice::WriteOnly)) QMessageBox::critical((QWidget *) 0, "Error", "Cannot open " + QString(pro)); else { Q3TextStream t(&f); QFileInfo tfi(target); QFileInfo pfi(pro); t << "TEMPLATE\t= " << tmplt << '\n'; t << "TARGET\t\t= " << tfi.fileName() << '\n'; if ((target.find('/') != -1) && (pro.find('/') != -1) && (tfi.dirPath(TRUE) != pfi.dirPath(TRUE))) t << "DESTDIR\t\t= " << tfi.dirPath(TRUE) << '\n'; if (! objectsdir.isEmpty()) t << "OBJECTS_DIR\t= " << objectsdir << '\n'; t << "CONFIG\t\t+= " << config << '\n'; if (!includepath.isEmpty()) t << "INCLUDEPATH\t= " << includepath << '\n'; if (!dependpath.isEmpty()) t << "DEPENDPATH\t= " << dependpath << '\n'; if (!defines.isEmpty()) t << "DEFINES\t\t= " << defines << '\n'; QString prodir = pfi.dirPath(TRUE); const Q3PtrVector<UmlArtifact> & arts = associatedArtifacts(); unsigned index; const char * sep; Q3CString ext; ext = CppSettings::headerExtension(); sep = "HEADERS\t\t= "; for (index = 0; index != arts.count(); index += 1) { UmlArtifact * art = arts[index]; if ((art->stereotype() == "source") && !art->cppHeader().isEmpty()) { QString s = art->way(prodir, TRUE); if (! s.isEmpty()) { t << sep << s << art->name() << '.' << ext; sep = " \\\n\t\t "; } } } t << '\n'; ext = CppSettings::sourceExtension(); sep = "SOURCES\t\t= "; for (index = 0; index != arts.count(); index += 1) { UmlArtifact * art = arts[index]; if ((art->stereotype() != "source") || !art->cppSource().isEmpty()) { QString s = art->way(prodir, FALSE); if (! s.isEmpty()) { t << sep << s << art->name(); if (art->stereotype() == "source") t << '.' << ext; sep = " \\\n\t\t "; } } } t << '\n' << footer << '\n'; f.close(); return; } } }
void UmlClass::need_artifact(const WrapperStr & nmsp) { if (parent()->kind() == aClassView) { UmlArtifact * cp; if ((cp = associatedArtifact()) == 0) { // search artifact #ifdef ROUNDTRIP if ((cp = Package::get_artifact()) != 0) { cp->addAssociatedClass(this); return; } #endif WrapperStr name = Package::get_fname(); int index; if (name.isEmpty()) { // defined in a source rather than a header // will create it own artifact name = this->name(); index = name.find('<'); if (index != -1) name = name.left(index); } UmlDeploymentView * cpv = ((UmlPackage *) parent()->parent())->get_deploymentview(nmsp); const QVector<UmlItem*> & children = cpv->children(); int n = (int) children.count(); for (index = 0; index != n; index += 1) { if ((children[index]->name() == name) && (children[index]->kind() == anArtifact)) { cp = (UmlArtifact *) children[index]; break; } } if (cp == 0) { // does not exist, create associated artifact if ((cp = UmlBaseArtifact::create(cpv, name)) == 0) { #ifdef REVERSE UmlCom::trace(WrapperStr("<font face=helvetica><b>cannot create artifact <i>") + Lex::quote(name) + "</i> under <i>" + Lex::quote(cpv->name()) + "</b></font><br>"); UmlCom::message(""); throw 0; #else QMessageBox::critical(0, "Fatal Error", WrapperStr("<font face=helvetica><b>cannot create artifact <i>") + Lex::quote(name) + "</i> under <i>" + Lex::quote(cpv->Name()) + "</b></font><br>"); QApplication::exit(1); #endif } cp->set_Stereotype("source"); cp->set_CppHeader(CppSettings::headerContent()); } cp->addAssociatedClass(this); } // source needed ? if (need_source() && cp->cppSource().isEmpty()) cp->set_CppSource(CppSettings::sourceContent()); } }