float Ship::KGh(){ float hulltotal = Wh() + Wm() + Wwo() + We() + Wspus() + Bunker(); float WKGh = (Wh() + Wwo()) * KGs(); float WKGe = We() * KGe(); float WKGm = (Wm() + Bunker()) * KGm(); float WKGspus = Wspus() * KGspus(); float armortot = Wmb() + Web() + Wub() + Wmd() + Wwd() + Wsd() + Wed() + Wblk(); float WKGmb = Wmb() * KGmb(); float WKGeb = Web() * KGeb(); float WKGub = Wub() * KGub(); float WKGmd = Wmd() * KGmd(); float WKGwd = Wwd() * KGwd(); float WKGsd = Wsd() * KGsd(); float WKGed = Wed() * KGed(); float WKGblk = Wblk() * KGblk(); float total = hulltotal + armortot; return (WKGh + WKGe + WKGm + WKGspus + WKGmb + WKGeb + WKGub + WKGmd + WKGwd + WKGsd + WKGed + WKGblk) / total; }
Foam::tmp<Foam::volScalarField> Foam::diameterModels::IATEsources::turbulentBreakUp::R() const { tmp<volScalarField> tR ( new volScalarField ( IOobject ( "R", iate_.phase().U().time().timeName(), iate_.phase().mesh() ), iate_.phase().U().mesh(), dimensionedScalar("R", dimless/dimTime, 0) ) ); volScalarField R = tR(); scalar Cti = Cti_.value(); scalar WeCr = WeCr_.value(); volScalarField Ut(this->Ut()); volScalarField We(this->We()); const volScalarField& d(iate_.d()()); forAll(R, celli) { if (We[celli] > WeCr) { R[celli] = (1.0/3.0) *Cti/d[celli] *Ut[celli] *sqrt(1 - WeCr/We[celli]) *exp(-WeCr/We[celli]); } } return tR; }
Spectrum PerspectiveCamera::Sample_Wi(const Interaction &ref, const Point2f &u, Vector3f *wi, Float *pdf, Point2f *pRaster, VisibilityTester *vis) const { // Uniformly sample a lens interaction _lensIntr_ Point2f pLens = lensRadius * ConcentricSampleDisk(u); Point3f pLensWorld = CameraToWorld(ref.time, Point3f(pLens.x, pLens.y, 0)); Interaction lensIntr(pLensWorld, ref.time, medium); lensIntr.n = Normal3f(CameraToWorld(ref.time, Vector3f(0, 0, 1))); // Populate arguments and compute the importance value *vis = VisibilityTester(ref, lensIntr); *wi = lensIntr.p - ref.p; Float dist = wi->Length(); *wi /= dist; // Compute PDF for importance arriving at _ref_ // Compute lens area of perspective camera Float lensArea = lensRadius != 0 ? (Pi * lensRadius * lensRadius) : 1; *pdf = (dist * dist) / (AbsDot(lensIntr.n, *wi) * lensArea); return We(lensIntr, -*wi, pRaster); }
float Ship::Hullship(){ return Wh() + Wwo() + Wm() + We() + Wspus() + Bunker(); }
void Ship::output(){ ofstream file; file.open("Report.txt"); file << "[table]" << endl; cout << fixed << setprecision(2) << "Length: \t\t\t\t" << v.Lpp << " m" << endl; file << fixed << setprecision(2) << "[tr][td]Length: \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[/td][td]" << v.Lpp << " m[/td][/tr]" << endl; cout << "Beam: \t\t\t\t\t" << v.B << " m" << endl; file << "[tr][td]Beam: [/td][td]" << v.B << " m[/td][/tr]" << endl; cout << "Draft: \t\t\t\t\t" << v.D << " m" << endl; file << "[tr][td]Draft: [/td][td]" << v.D << " m[/td][/tr]" << endl; cout << "Freeboard: \t\t\t\t" << v.fB << " m" << endl; file << "[tr][td]Freeboard: [/td][td]" << v.fB << " m[/td][/tr]" << endl; cout << setprecision(3) << "Block Coefficient: \t\t\t" << Cb() << endl; file << setprecision(3) << "[tr][td]Block Coefficient: [/td][td]" << Cb() << "[/td][/tr]" << endl; cout << setprecision(0) << "Displacement: \t\t\t\t" << Vol() << " t" << endl; file << setprecision(0) << "[tr][td]Displacement: [/td][td]" << Vol() << " t[/td][/tr]" << endl; cout << "Lightship: \t\t\t\t" << Wh() + Wwo() + Wm() + We() + Wspus() + Bunker() << " t" << endl; file << "[tr][td]Lightship: [/td][td]" << Lightship() << " t[/td][/tr]" << endl; cout << setprecision(1) << "\nMax Speed: \t\t\t\t" << v.Vk << " kn" << endl; file << setprecision(1) << "\n[tr][td]Max Speed: [/td][td]" << v.Vk << " kn[/td][/tr]" << endl; cout << "Cruise Speed: \t\t\t\t" << v.Vc << " kn / " << v.Range << " nm" << endl; file << "[tr][td]Cruise Speed: [/td][td]" << v.Vc << " kn / " << v.Range << " nm[/td][/tr]" << endl; cout << "Engine: \t\t\t\t"; file << "[tr][td]Engine: [/td][td]"; switch(e.Gear){ case Direct: cout << "Direct "; file << "Direct "; break; case Geared: cout << "Geared "; file << "Geared "; break; case Turbo_Electric: cout << "Turbo-Electric "; file << "Turbo-Electric "; break; default: cout << "Unknown"; file << "Unknown"; } switch(e.Eng){ case Diesel2stk: cout << "Two Stroke Diesel" << endl; file << "Two Stroke Diesel"; break; case Diesel4stk: cout << "Four Stroke Diesel" << endl; file << "Four Stroke Diesel" << endl; break; case QuadExp: cout << "Quadruple Expansion Reciprocating Engine" << endl; file << "Quadruple Expansion Reciprocating Engine"; break; case TripExp: cout << "Triple Expansion Reciprocating Engine" << endl; file << "Triple Expansion Reciprocating Engine"; break; case SimExp: cout << "Simple Reciprocating Engine" << endl; file << "Simple Reciprocating Engine"; break; case SteamTur: cout << "Steam Turbine" << endl; file << "Steam Turbine"; break; default: cout << endl; } file << "[/td][/tr]" << endl; cout << setprecision(0) << "Power Delivered: \t\t\t" << Pd(v.Vk) << " hp" << endl; file << setprecision(0) << "[tr][td]Power Delivered: [/td][td]" << Pd(v.Vk) << " hp[/td][/tr]" << endl; cout << setprecision(2) << "Total Efficiency: \t\t\t" << NUt()*100 << "%" << endl; file << setprecision(2) << "[tr][td]Total Efficiency: [/td][td]" << NUt()*100 << "%[/td][/tr]" << endl; cout << setprecision(3) << "Froude Number: \t\t\t\t" << Fn() << endl; file << setprecision(3) << "[tr][td]Froude Number: [/td][td]" << Fn() << "[/td][/tr]" << endl; cout << setprecision(0) << "Bunker Size: \t\t\t\t" << Bunker() << " t" << endl; file << setprecision(0) << "[tr][td]Bunker Size: [/td][td]" << Bunker() << " t[/td][/tr]" << endl; cout << "Service Allowance: \t\t\t" << e.SA << "%" << endl; file << "[tr][td]Service Allowance: [/td][td]" << e.SA << "%[/td][/tr]" << endl; cout << setprecision(2); file << setprecision(2); cout << "Length of Superstructure: \t\t" << v.Lspus << " m" << endl; file << "[tr][td]Length of Superstructure: [/td][td]" << v.Lspus << " m[/td][/tr]" << endl; cout << "Aftbody Shape: \t\t\t\t"; file << "[tr][td]Aftbody Shape: [/td][td]"; switch(e.Faa){ case V: cout << "V" << endl; file << "V"; break; case U: cout << "U" << endl; file << "U"; break; case N: cout << "N" << endl; file << "N"; break; default: cout << "N" << endl; file << "N"; } file << "[/td][/tr]"; cout << "\nLongitudinal Center of Buoyancy: \t" << lcb() << "%" << endl; file << "\n[tr][td]Longitudinal Center of Buoyancy: [/td][td]" << lcb() << "% / " << lcb()*v.Lpp << " m from midpoint[/td][/tr]" << endl; cout << "Longitudinal Center of Gravity: \t" << lcg() << "%" << endl; file << "[tr][td]Longitudinal Center of Gravity: [/td][td]" << lcg() << "% / " << lcg()*v.Lpp << " m from midpoint[/td][/tr]" << endl; cout << "Vertical Center of Gravity: \t\t" << KGh() << " m" << endl; file << "[tr][td]Vertical Center of Gravity: [/td][td]" << KGh() << " m[/td][/tr]" << endl; cout << "Metacentric Height: \t\t\t" << GM() << " m" << endl; file << "[tr][td]Metacentric Height: [/td][td]" << GM() << " m[/td][/tr]" << endl; cout << "Roll Period: \t\t\t\t" << TR() << " s" << endl; file << "[tr][td]Roll Period: [/td][td]" << TR() << " s[/td][/tr]" << endl; cout << "\nBow Entrance Angle: \t\t\t" << iE() << " deg" << endl; file << "\n[tr][td]Bow Entrance Angle: [/td][td]" << iE() << " deg[/td][/tr]" << endl; cout << "Length of Engine Room: \t\t\t" << Lcm() << " m" << endl; file << "[tr][td]Length of Engine Room: [/td][td]" << Lcm() << " m[/td][/tr]" << endl; cout << setprecision(0) << "\nMain Belt: \t\t\t\t" << arm.mb_Ttop << " / " << arm.mb_Tbot << " mm at " << arm.b_deg << " degrees, " << arm.b_L << " m long with " << arm.b_H << " m above and " << arm.b_Db << " m below water" << endl; file << setprecision(0) << "\n[tr][td]Main Belt: [/td][td]" << arm.mb_Ttop << " / " << arm.mb_Tbot << " mm, " << arm.b_L << " m long with " << arm.b_H << " m above and " << arm.b_Db << " m below water[/td][/tr]" << endl; cout << "End Belt: \t\t\t\t" << arm.eb_Ttop << " / " << arm.eb_Tbot << " mm" << endl; file << "[tr][td]End Belt: [/td][td]" << arm.eb_Ttop << " / " << arm.eb_Tbot << " mm[/td][/tr]" << endl; cout << "Upper Belt: \t\t\t\t" << arm.ub_Ttop << " / " << arm.ub_Tbot << " mm, " << arm.b_uL << " m long" << endl; file << "[tr][td]Upper Belt: [/td][td]" << arm.ub_Ttop << " / " << arm.ub_Tbot << " mm, " << arm.b_uL << " m long[/td][/tr]" << endl; cout << "Main Deck: \t\t\t\t" << arm.md_T << " mm covering " << arm.md_P << "% / " << arm.md_P * v.Lpp << " m of deck" << endl; file << "[tr][td]Main Deck: [/td][td]" << arm.md_T << " m covering " << arm.md_P << "% / " << arm.md_P * v.Lpp << " m of deck[/td][/tr]" << endl; cout << "Weather Deck: \t\t\t\t" << arm.wd_T << " mm covering " << arm.wd_P << "% / " << arm.wd_P * v.Lpp << " m of deck" << endl; file << "[tr][td]Weather Deck: [/td][td]" << arm.wd_T << " m covering " << arm.wd_P << "% / " << arm.wd_P * v.Lpp << " m of deck[/td][/tr]" << endl; cout << "Splinter Deck: \t\t\t\t" << arm.sd_T << " mm covering " << arm.sd_P << "% / " << arm.sd_P * v.Lpp << " m of deck" << endl; file << "[tr][td]Splinter Deck: [/td][td]" << arm.sd_T << " m covering " << arm.sd_P << "% / " << arm.sd_P * v.Lpp << " m of deck[/td][/tr]" << endl; cout << "Ends Deck: \t\t\t\t" << arm.ed_T << " mm" << endl; file << "[tr][td]Ends Deck: [/td][td]" << arm.ed_T << " mm[/td][/tr]" << endl; cout << "Bulkhead: \t\t\t\t" << arm.blk_T << " mm in " << arm.blk_Lct << "x" << arm.blk_D << " m layers, " << arm.blk_L << " m long, " << arm.blk_H << " m tall" << endl; file << "[tr][td]Bulkhead: [/td][td]" << arm.blk_T << " mm in " << arm.blk_Lct << "x" << arm.blk_D << " m layers, " << arm.blk_L << " m long, " << arm.blk_H << " m tall[/td][/tr]" << endl; file << "[/table]" << endl; file.close(); }
//***************************************************************************** void CHTMLWidget::StartElement( //Expat callback function: Process XML start tag, and attributes. // //Params: const XML_Char *name, const XML_Char **atts) { //Get tag type (assume no special chars). const HTMLTagType eTagType = ParseTag(name); if (wstrBuffer.length()) Flush(); ++aeTagLevel[eTagType]; //Get id/name attribute { static const WCHAR wszID[] = {We('i'),We('d'),We(0)}; static const WCHAR wszNAME[] = {We('n'),We('a'),We('m'),We('e'),We(0)}; WSTRING tmp = GetAttr(wszID, atts); if (tmp.empty()) tmp = GetAttr(wszNAME, atts); if (!tmp.empty()) mIdmap.insert(std::make_pair(tmp, this->wY)); } switch (eTagType) { case BODY_Tag: { static const WCHAR wszBgcolor[] = {We('b'),We('g'),We('c'),We('o'),We('l'),We('o'),We('r'),We(0)}; WSTRING bgcolor = GetAttr(wszBgcolor, atts); if (bgcolor.size()) this->wstrBGColor = bgcolor; break; } case UL_Tag: case OL_Tag: this->swOLstack.push(this->wOLcounter); this->wOLcounter = (eTagType == OL_Tag ? 1 : 0); this->wMargin += LISTINDENT; NewLine(this->swOLstack.size() == 1); break; case H1_Tag: case H2_Tag: case H3_Tag: NewLine(); break; case TITLE_Tag: wstrTitle = wszEmpty; break; case A_Tag: swstrLink.push(GetAttr(wszHREF, atts)); break; case B_Tag: break; case HR_Tag: case BR_Tag: NewLine(true); break; case IMG_Tag: { static const WCHAR wszSrc[] = {We('s'),We('r'),We('c'),We(0)}; WSTRING imageURL = this->wstrBasePath; imageURL += wszSlash; imageURL += GetAttr(wszSrc, atts); CImageWidget *pImage = new CImageWidget(0, this->wX + this->wMargin, this->wY, imageURL.c_str()); ASSERT(pImage); AddWidget(pImage); this->wY += pImage->GetH(); this->wX = 0; //next thing goes on new line break; } case P_Tag: this->wY += static_cast<UINT>(g_pTheFM->GetFontLineHeight(FONTLIB::F_Text) * 2/3); break; case LI_Tag: { //Use image as bullet in stead ? static const WCHAR wszItem[] = {We('*'),We(' '),We(0)}; NewLine(); if (this->wOLcounter) { WCHAR wszBuf[33]; wstrBuffer = (WSTRING)_itow(this->wOLcounter, wszBuf, 10) + wszPeriod + wszSpace; ++this->wOLcounter; } else wstrBuffer = wszItem; Flush(true); this->bSkipSpace = true; break; } case TABLE_Tag: NewLine(); vwColumns.clear(); //Fall through case TR_Tag: this->wCurrentColumn = 0; break; case TD_Tag: { if (this->wCurrentColumn >= vwColumns.size()) { static const WCHAR wszWidth[] = {We('w'),We('i'),We('d'),We('t'),We('h'),We(0)}; WSTRING wstrWidthAttr = GetAttr(wszWidth, atts); this->wTDWidth = wstrWidthAttr.length() > 0 ? _Wtoi(wstrWidthAttr.c_str()) : 0; vwColumns.push_back(this->wX += 32); } else { this->wX = vwColumns[this->wCurrentColumn]; this->wTDWidth = 0; } ++this->wCurrentColumn; this->bSkipSpace = true; break; } default: break; } }
//***************************************************************************** bool CHTMLWidget::Parse( //Parse text buffer and add child widgets for each part. // //Params: const CStretchyBuffer &text) //(in) Text to parse. // //Returns: True if parse was successful, false if there was a parse error. { //Renderer init. ClearChildren(); this->wCurrentColumn = this->wX = 0; this->wY = this->wMargin; this->bSkipSpace = true; this->dwCurrentLinkTag = this->dwLinkTagStart; for (int i = First_Tag; i <= Tag_Count; ++i) // Including unknown aeTagLevel[i] = 0; mIdmap.clear(); static const WCHAR defaultColor[] = {We('F'),We('F'),We('F'),We('F'),We('F'),We('F'),We(0)}; this->wstrBGColor = defaultColor; //Parser init. XML_Parser parser = XML_ParserCreate(NULL); XML_SetUserData(parser, this); XML_SetElementHandler(parser, StartElement_cb, EndElement_cb); XML_SetCharacterDataHandler(parser, InElement_cb); // XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_NEVER); bool bResult = true; char *buf = (char*)(BYTE*)text; //size - 2 seems to fix "invalid token" errors at EOF (even at empty files). const UINT size = text.Size() - 2; //Parse the XML. static const char entities[] = "<?xml version=\"1.0\" encoding=\"" "UTF-8" "\"?>" "<!DOCTYPE html [" "<!ENTITY nbsp \"\xc2\xa0\">" //utf-8 for 0xa0 = unicode nbsp "]>"; if ((XML_Parse(parser, entities, strlen(entities), false) == XML_STATUS_ERROR) || (XML_Parse(parser, buf, size, true) == XML_STATUS_ERROR)) { //Some problem occurred. char errorStr[256]; _snprintf(errorStr, 256, "HTML Parse Error: %s at line %u:%u" NEWLINE, XML_ErrorString(XML_GetErrorCode(parser)), (UINT)XML_GetCurrentLineNumber(parser), (UINT)XML_GetCurrentColumnNumber(parser)); CFiles Files; Files.AppendErrorLog((char *)errorStr); #ifdef RUSSIAN_BUILD //Fix unsupported KOI8 encoded Cyrillic chars. // ConvertCyrillicEncodedXMLToUTF8(text); #endif AsciiToUnicode(errorStr, this->wstrStatus); bResult = false; } //Parser clean-up. XML_ParserFree(parser); NewLine(); //once done, ensure final line of text is included in height NewLine(true); //...and have a blank line at the bottom to look good //Render surface to display on screen. bool bCanResize = CanResize(); if (bCanResize) { this->pParent->ScrollAbsolute(0, 0); //scroll to top of page if (this->wY < this->pParent->GetH()) //stretch surface to fill container this->wY = this->pParent->GetH(); } UpdateHTMLSurface(); //Resize (if possible). if (bCanResize) Resize(this->pHTMLSurface->w, this->pHTMLSurface->h); return bResult; }
//***************************************************************************** void CHTMLWidget::Flush(bool bInMargin) //Flush the output buffer. { if ((aeTagLevel[UL_Tag] || aeTagLevel[OL_Tag]) && !aeTagLevel[LI_Tag]) { wstrBuffer = wszEmpty; return; } if (aeTagLevel[TITLE_Tag]) { wstrTitle = wstrBuffer; } else { CLabelWidget *pText; if (bInMargin) this->wX = 0; if (aeTagLevel[A_Tag] && !swstrLink.empty() && !swstrLink.top().empty()) { UINT eFontType = FONTLIB::F_TextHyperlink; UINT eFontType2 = FONTLIB::F_TextActiveHyperlink; static const WCHAR wszWorldLink[] = {We('h'),We('t'),We('t'),We('p'),We(':'),We(0)}; if (!swstrLink.top().compare(0, 5, wszWorldLink)) { eFontType = FONTLIB::F_TextExtHyperlink; eFontType2 = FONTLIB::F_TextActiveExtHyperlink; } pText = new CHyperLinkWidget(this->dwCurrentLinkTag++, this->wMargin, this->wY, this->w - this->wMargin * 2, this->h, eFontType, eFontType2, wstrBuffer.c_str(), swstrLink.top().c_str(), true, this->wX); } else { UINT eFontType = FONTLIB::F_Text; if (aeTagLevel[H3_Tag]) eFontType = FONTLIB::F_TextHead3; else if (aeTagLevel[B_Tag]) eFontType = FONTLIB::F_TextBold; else if (aeTagLevel[I_Tag]) eFontType = FONTLIB::F_TextItalic; else if (aeTagLevel[U_Tag]) eFontType = FONTLIB::F_TextUnderline; // Plain text. pText = new CLabelWidget(0, this->wMargin, this->wY, this->w - this->wMargin * 2, this->h, eFontType, wstrBuffer.c_str(), true, this->wX); } UINT wW, wH; const UINT wLastW = pText->GetTextWidthHeight(wW, wH, this->wX); const UINT wLineH = g_pTheFM->GetFontLineHeight(pText->GetFontType()); if (bInMargin) pText->Move(pText->GetX() - (int)wW, pText->GetY()); else { this->wX = wLastW; this->wY += wH - wLineH; if (this->wX >= this->w - this->wMargin * 2) { this->wX = 0; this->wY += wLineH; if (this->wX >= this->w - this->wMargin * 2) this->wX = 0; } } AddWidget(pText); } wstrBuffer = wszEmpty; }
* Contributor(s): * * ***** END LICENSE BLOCK ***** */ #include "HTMLWidget.h" #include "BitmapManager.h" #include "LabelWidget.h" #include "HyperLinkWidget.h" #include "FontManager.h" #include "ScrollableWidget.h" #include "ImageWidget.h" #include <BackEndLib/Files.h> #include <BackEndLib/Ports.h> // stricmp //***************************************************************************** static const WCHAR wszHREF[] = {We('h'),We('r'),We('e'),We('f'),We(0)}; static const UINT LISTINDENT = 42; //***************************************************************************** // //Expat callback entrypoints (private) // void StartElement_cb ( void *pHTMLWidget, // (in) Pointer to HTML Widget const XML_Char *name, const XML_Char **atts) { ((CHTMLWidget*)pHTMLWidget)->StartElement(name, atts); } void InElement_cb (