//разбивает строку на несколько с учётом максимально допустимой ширины //str - исходная строка //AlignText - результирующий текст //Width - максимальная ширина void CTextAlign::StringAlign ( const AnsiString &str, TStrings *AlignText, int Width ) { if ( Width <= 0 ) { AlignText->Add ( str ); return; } if ( str.Length() <= Width ) { AlignText->Add ( str ); return; } AnsiString FirstPart = str.SubString ( 1, Width ); AnsiString LastPart = str.SubString ( Width + 1, str.Length() - Width ); int pos = FirstPart.LastDelimiter(" "); if ( pos == 0 ) { //если нет пробелов в строке AlignText->Add ( FirstPart ); StringAlign ( LastPart, AlignText, Width ); }else { AlignText->Add ( FirstPart.SubString ( 1, pos ) ); LastPart = FirstPart.SubString ( pos + 1, FirstPart.Length() - pos ) + LastPart; StringAlign ( LastPart, AlignText, Width ); } }
//----------------------------------------------------------------------------- bool withPath( AnsiString asPath ) { if ( asPath.LastDelimiter(":\\") > 0 ) return true; else return false; }
//--------------------------------------------------------------------------- bool getPathFromStr( AnsiString asStr, AnsiString &asPath ) { int iLD = asStr.LastDelimiter(":\\"); if (iLD <= 0) return false; asPath = asStr.SubString( 1, iLD ); return true; }
//--------------------------------------------------------------------------- void __fastcall TGammaMeasurementForm::Button_MeasureClick(TObject * Sender) { using namespace std; using namespace cms::util; using namespace cms::measure; using namespace cms::measure::meter; MainForm->setMeterMeasurementWaitTimes(); String_ptr filename = this->TOutputFileFrame1->getOutputFilename(); string stlfilename = filename->c_str(); if (!Util::deleteExist(stlfilename)) { ShowMessage("File is locked!"); return; } bool imageMeasure = CheckBox_ImageMeasure->Checked; try { Button_Measure->Enabled = false; MainForm->showProgress(ProgressBar1); if (imageMeasure) //20140609 skyforce, 可用圖片做pattern的量測功能 { AnsiString Dir = "D:\\"; SelectDirectory("選擇目錄", "", Dir); AnsiString finalDirName = Dir.SubString(Dir.LastDelimiter("\\") + 1, Dir.Length()); // this->Edit_Directory->Text = Dir + " \\ "; int start = this->Edit_StartLevel->Text.ToInt(); int end = this->Edit_EndLevel->Text.ToInt(); int step = this->ComboBox_LevelStep->Text.ToInt(); AnsiString s; // int waitTimes = MainForm->geti bptr < MeterMeasurement > mm = MainForm->mm; int waitTimes = mm->WaitTimes; bptr < Meter > meter = mm->getMeter(); XYZ_vector_ptr XYZVector(new XYZ_vector()); MeasureWindow->Visible = true; for (int graylevel = start; graylevel >= end; graylevel -= step) { AnsiString filename = s.sprintf("%s\\%s_%03d.bmp", Dir, finalDirName, graylevel); // AnsiString filename = s.sprintf(" % d.", graylevel) + " bmp "; if (FileExists(filename)) { MeasureWindow->setImageFilename(filename.c_str()); Application->ProcessMessages(); Sleep(waitTimes); if (MainForm->linkCA210) { double_array XYZValues = meter->triggerMeasurementInXYZ(); XYZ_ptr XYZ(new Indep::CIEXYZ(XYZValues)); XYZVector->push_back(XYZ); } else { XYZ_ptr XYZ(new Indep::CIEXYZ(1, 2, 3)); XYZVector->push_back(XYZ); } } else { ShowMessage("Image " + filename + " is not exisit ! Stop measure."); break; } } MeasureWindow->Visible = false; MeasureWindow->setImageOff(); // String_ptr astr = this->TOutputFileFrame1->getOutputFilename(); // string filename = astr->c_str(); if (XYZVector->size() != 0) { Util::storeXYZxyVector(stlfilename, XYZVector, "no"); ShowMessage("Ok!"); Util::shellExecute(stlfilename); } } else { bool_vector_ptr rgbw(new bool_vector(4)); int_vector_ptr background(new int_vector(3)); bool flicker = this->CheckBox_FlickerFMA->Checked; (*rgbw)[0] = this->CheckBox_R->Checked; (*rgbw)[1] = this->CheckBox_G->Checked; (*rgbw)[2] = this->CheckBox_B->Checked; (*rgbw)[3] = this->CheckBox_W->Checked; (*background)[0] = Edit_BackgroundR->Text.ToInt(); (*background)[1] = Edit_BackgroundG->Text.ToInt(); (*background)[2] = Edit_BackgroundB->Text.ToInt(); bool customPattern = RadioButton_TCONInputCustomPattern->Checked; if (customPattern) { (*rgbw)[0] = false; (*rgbw)[1] = false; (*rgbw)[2] = false; (*rgbw)[3] = true; (*background)[0] = 0; (*background)[1] = 0; (*background)[2] = 0; } if (false == (*rgbw)[0] && false == (*rgbw)[1] && false == (*rgbw)[2] && false == (*rgbw)[3]) { ShowMessage("Select at least one color."); return; } if (measure (rgbw, background, getMeasureCondition(), flicker, stlfilename)) { MainForm->stopProgress(ProgressBar1); ShowMessage(" Ok ! "); Util::shellExecute(stlfilename); //Open file } } } __finally { MainForm->stopProgress(ProgressBar1); Button_Measure->Enabled = true; } }
//--------------------------------------------------------------------------- // Check to see if SelfImage is up-to-date - notify the user if it isn't // void CheckVersion(void) { TDateTime *dtLastCheck = NULL; char *filename = NULL; char *buffer = NULL; char *verbuff = NULL; unsigned nVersionInfoSize; int nBuildPos; static AnsiString sMyVersion = ""; static int nMyBuild = 0; AnsiString sCurrentVersion, sURL; int nCurrentBuild = 0; TIdHTTP *HTTP; DWORD nDummy; __ENTERFUNCTION__; try { try { formSelfImageNewVersionNotify = NULL; if (!SelfImageConfig->Values["Update Notify"]) { LOG(LOG_DEBUG, "Update Notify is turned off - not checking for new version."); goto END; // Ugly - C++ Builder silently ignores a __finally block if a return is process from a nested try. } // if (!SelfImageConfig->Values["Update Notify"]) if (String(SelfImageConfig->Values["Last Version Check"]).IsEmpty()) SelfImageConfig->Values["Last Version Check"] = (Now()-1).DateTimeString(); dtLastCheck = new TDateTime(String(SelfImageConfig->Values["Last Version Check"])); if (!DaysBetween(Now(), *dtLastCheck)) { LOG1(LOG_DEBUG, "Last new version check was performed %s - not checking again.", dtLastCheck->DateTimeString().c_str()); goto END; // Ugly - C++ Builder silently ignores a __finally block if a return is process from a nested try. } // if (!DaysBetween(Now(), *dtLastCheck)) SelfImageConfig->Values["Last Version Check"] = Now().DateTimeString(); // Get this executable's version - this is a pain, so let's just do it once for each time SelfImage is instantiated if (!nMyBuild) { LOG(LOG_DEBUG, "Retrieving internal version number."); filename = (char *)malloc(MAXPATH); GetModuleFileName(HInstance, filename, MAXPATH); nVersionInfoSize = GetFileVersionInfoSize(filename, &nDummy); // These following three exceptions should never make it to the user except through the logs in a debug build. // Since they are only for logging, they are allowed to have text that doesn't come from the string table. if (!nVersionInfoSize) throw ESelfImageSystemError("GetFileVersionInfoSize() failed: " + GetLastErrorMessage()); buffer = (char *)malloc(nVersionInfoSize); if (!GetFileVersionInfo(filename, NULL, nVersionInfoSize, buffer)) throw ESelfImageSystemError("GetFileVersionInfo() failed:" + GetLastErrorMessage()); if (!VerQueryValue(buffer, "\\StringFileInfo\\100904E4\\FileVersion", (void **)&verbuff, NULL)) throw ESelfImageSystemError("VerQueryValue() failed:" + GetLastErrorMessage()); sMyVersion = verbuff; nBuildPos = sMyVersion.LastDelimiter("."); nMyBuild = sMyVersion.SubString(nBuildPos + 1, sMyVersion.Length() - nBuildPos).ToInt(); sMyVersion = sMyVersion.SubString(1,nBuildPos-1) + " (Build " + String(nMyBuild) + ")"; LOG1(LOG_MESSAGE, "Internal version string retrieved from resources: \"%s\".", sMyVersion.c_str()); } // if (sMyVersion.IsEmpty()) // Get SelfImage's current version from the interweb - woo, this is cool HTTP = new TIdHTTP(NULL); sURL = SelfImageConfig->Values["Version URL"]; LOG1(LOG_DEBUG, "Attempting to retrieve version string from URL \"%s\".", sURL.c_str()); try { sCurrentVersion = HTTP->Get(SelfImageConfig->Values["Version URL"]); nBuildPos = sCurrentVersion.Pos("(Build "); nCurrentBuild = sCurrentVersion.SubString(nBuildPos + 7, sCurrentVersion.Length() - nBuildPos - 7).ToInt(); } catch (...) { sCurrentVersion = ""; } delete HTTP; #ifdef __LOGGINGENABLED__ if (!sCurrentVersion.IsEmpty()) LOG2(LOG_MESSAGE, "Version string \"%s\" retrieved from %s.", sCurrentVersion.c_str(), sURL.c_str()) else LOG2(LOG_WARNING, "Unable to retrieve version string from URL \"%s\": %s", sURL.c_str(), HTTP->ResponseText.c_str()); #endif // Compare the two... if (nCurrentBuild && nMyBuild < nCurrentBuild && sCurrentVersion != String(SelfImageConfig->Values["Notify Squelch"])) { LOG(LOG_DEBUG, "Notifying user of new version."); formSelfImageNewVersionNotify = new TformSelfImageNewVersionNotify(NULL, sMyVersion, sCurrentVersion); if (formSelfImageNewVersionNotify->ShowModal() == mrCancel) SelfImageConfig->Values["Notify Squelch"] = sCurrentVersion; } // if (different versions) } // inner try catch (Exception &e) { LOG2(LOG_ERROR, "Exception of type \"%s\" raised during new version check with message \"%s\"", String(e.ClassName()).c_str(), e.Message.c_str()); } // catch } // outer try __finally { if (dtLastCheck) delete dtLastCheck; if (filename) free(filename); if (buffer) free(buffer); if (formSelfImageNewVersionNotify) { delete formSelfImageNewVersionNotify; formSelfImageNewVersionNotify = NULL; } // if (formSelfImageNewVersionNotify) } END: __RETURNFUNCTION__; } // void CheckVersion(void)