روش های پیشرفت

روش های پیشرفت

روش های پیشرفت
روش های پیشرفت برای ایجاد و به روز رسانی اطلاعات پیشرفت در نوار وضعیت، در یک شی فرم پیشرفت و در یک کادر محاوره ای استفاده می شود.

 
Name
Syntax
Description
setProgressInterval
setProgressInterval(String message, int intervalStart, int intervalEnd)
Sets a progress interval to use for the top-level progress and display message at that level. The top level will go from intervalStart to intervalEnd as the second level goes from 0 to 100. As the second level increases, the top level is increased by (intervalEnd – intervalStart) * (second level progress (0-100) / 100).
The value for intervalStart must be between 0 and intervalEnd, and the value for intervalEnd must be between intervalStart and 100.
Calling this method implicitly resets any manual progress previously set by calls to setProgress().
setProgress
setProgress(int value, String message)
Sets a value for the user-controlled progress level. By default, this is the top level, but if a progress interval is active (setProgressInterval has been called and resetProgress has not been called after that), then it is the second level.
setProgress
setProgress(int value)
Same as setProgress(message, value), but uses the latest message or an empty string (if no message has been set).
resetProgress
resetProgress()
Removes all progress levels and resets progress to 0 and the message to an empty string.
showIndeterminateProgress
showIndeterminateProgress(String message)
Shows a progress dialog box with an indeterminate progress bar, given message and a cancel button.
showIndeterminateProgress
showIndeterminateProgress(String message, boolean cancelButton)
Shows a progress dialog box with an indeterminate progress bar, given message and an optional cancel button.
showProgress
showProgress()
Shows a progress dialog box with a cancel button. No model progress is included.
showProgress
showProgress(boolean modelProgress)
Shows a progress dialog box with a cancel button and an optional model progress.
showProgress
showProgress(boolean modelProgress, boolean addSecondLevel)
Shows a progress dialog box with a cancel button, optional model progress, and one or two levels of progress information. Two levels can only be used if modelProgress is true.
showProgress
showProgress(boolean modelProgress, boolean addSecondLevel, boolean cancelButton)
Shows a progress dialog box with optional model progress, one or two levels, and possibly a cancel button. Two levels can only be used if modelProgress is true.
closeProgress
closeProgress()
Closes the currently shown progress dialog box.
startProgress
startProgress(String name)
startProgress(FormObject progressBar)
Resets the value of the given progress bar form object name to 0. The progress bar to control can be specified with an absolute path, such as form1/progressbar1, or a name relative to the context from which the method was called.
Nothing is done if no progress bar corresponding to the given name is found.
setProgressBar
setProgressBar(String name, int workDone, String message)
setProgressBar(FormObject progressBar, int workDone, String message)
Sets the value of the given progress bar form object name in the range 0-100 and the associated progress message. Values out of range are converted to 0 or 100. The progress bar to control can be specified with an absolute path, such as form1/progressbar1, or a name relative to the context from which the method was called.
Nothing is done if no progress bar corresponding to the given name is found, or if the progress bar is used for showing model progress.
setProgressBar
setProgressBar(String name, int workDone)
setProgressBar(FormObject progressBar, int workDone)
Same as above, but does not update the progress message.

کد مثال
EXAMPLE CODE
showProgress(true, true, true);
/* Opens a progress dialog box with cancel button showing two levels of progress. The values shown in progress dialog box will be updated to match the two levels of progress. */
setProgressInterval(“Preparing application”, 0, 20);
/* Sets the current progress scale to go from 0 to 20. This means that the top-level progress will go from 0 to 20 when second-level progress goes from 0 to 100. */
setProgress(0, “Init step 1”);
/* Sets the second-level progress to 0 and the second-level progress message to “Init step 1”. */
// do some work
setProgress(40);
/* Sets the second-level progress to 40, this causes the top-level progress to be updated to 8 (40 % of 0-20). */
// do some work
setProgress(80, “Init step 2”);
/* Sets the second-level progress to 80 and the progress message to “Init step 2”. The top-level message is still “Preparing application” and top-level progress is now 16. */
// do some work
setProgressInterval(“Meshing”, 20, 40);
/* Sets the top-level interval to 20 – 40 and the progress message to “Meshing” at this point the value shown at the top-level will be 20. The second-level progress is cleared when the top-level interval is changed. */
<call-meshing algorithm here>
/* The progress messages and values from the meshing algorithm are shown at the second-level progress. The top-level progress message will be “Meshing”, but the top-level progress advances from 20 to 40 while second-level progress advances from 0 to 100. */
setProgressInterval(“Solving”, 40, 100);
/* The top-level progress message is changed to “Solving” and its value to 40.
<call-solver>
/* Similar to meshing, the progress messages and values from the solver are shown in the second-level progress bar and the top-level progress value goes from 40 to 100 while the solver progress goes from 0 to 100. */
closeProgress();
اطلاعات پیشرفت برنامه
اطلاعات پیشرفت را می توان به سه روش مختلف نمایش داد: در نوار وضعیت، در یک شی فرم پیشرفت و در یک کادر محاوره ای. اطلاعات پیشرفت برنامه توسط متدهای setProgress کنترل می شود که یک عدد صحیح بین 0 تا 100 و یک پیام اختیاری را به عنوان ورودی خود می گیرند. عدد صحیح نشان دهنده میزان پیشرفت نوار پیشرفت نمایش داده شده است. اگر هیچ پیامی ارائه نشد، از آخرین پیام ارائه شده استفاده می شود. مثلا:
setProgress (10، “محاسبات داده ها”)؛
setProgress(25);
این داده‌های محاسباتی را به عنوان پیام پیشرفت حفظ می‌کند.
اگر می خواهید پیشرفت سفارشی را در نوار وظیفه و وضعیت نشان دهید، از روش setProgress به تنهایی استفاده کنید. هنگامی که این کار را انجام دادید، آن نوار پیشرفت دیگر با اطلاعات پیشرفت از مدل COMSOL به روز نمی شود، بلکه برای تغییرات در مقدار آن کاملاً به تماس های بعدی به setProgress وابسته است. قبل از آن یک فراخوانی به showProgress بدهید تا کادر گفتگوی پیشرفت داخلی نیز نمایش داده شود، زیر را ببینید.
توجه داشته باشید که اطلاعات پیشرفت از مدل COMSOL در بین تماس‌های setProgress نشان داده نمی‌شود . پیشرفت بین فراخوانی های متد بازنشانی می شود. اگر می خواهید مراحل سفارشی پیشرفت در متدها را با پیشرفت مدل داخلی ترکیب کنید، به جای آن از setProgressInterval استفاده کنید.
با setProgressInterval ، می توانید دو سطح بالای اطلاعات پیشرفت را کنترل کنید. سطح دوم را می توان در یک کادر محاوره ای پیشرفت و یک شی فرم نوار پیشرفت نمایش داد، بخش کد زیر را ببینید. سطح پیشرفت دوم، که توسط محاسبه پیشرفت سفارشی شما کنترل می شود، به سطح اول متصل است به طوری که یک بازه در سطح بالا با کل سطح دوم مطابقت دارد. بنابراین اگر بازه 0-50 باشد، زمانی که پیشرفت سطح دوم به 40 برسد، برای مثال، سطح اول روی 20 تنظیم می شود (=(40/100)*50).
کاربردهای مهم متد setProgressInterval در زیر ذکر شده است:
ترکیب تماس ها با مدل COMSOL به طوری که پیشرفت مداوم از 0 تا 100 داشته باشید.
محاسبه چندین مطالعه و همچنین ارزیابی چندین نمودار. قبل از هر فراخوانی با متدهای داخلی با فاصله زمانی که محاسبه هر مدل به طور تقریبی چقدر زمان می برد، setProgressInterval را فراخوانی کنید. مثلا:
setProgressInterval(“راه حل محاسباتی”، 0، 80);
model.study(“std1”).run();
setProgressInterval(“Plotting”, 80, 100);
useGraphics(model.result(“pg3”)، “energy_response_plot/graphics1”);
ترکیب یک یا چند تماس با متدهای COMSOL داخلی با روش‌های سفارشی که به خودی خود زمان قابل توجهی می‌برند. در این مورد، مانند مثال قبلی، از setProgressInterval استفاده کنید ، سپس از کد سفارشی خود با فراخوانی مناسب به setProgress استفاده کنید. این تماس ها باید از 0 تا 100 اجرا شوند زیرا سطح پیشرفت دوم را کنترل می کنند. مثلا:
setProgressInterval(“راه حل محاسباتی”، 0، 60);
model.study(“std1”).run();
setProgressInterval(“Working”, 60, 80);
setProgress(0، “پیام خاص در مورد کاری که انجام می دهم”);
//…
// کدی که کاری انجام می دهد
//…
setProgress(60);
اگر در یک برنامه در حال اجرا می خواهید دیگر از فواصل پیشرفت استفاده نکنید، با resetProgress تماس بگیرید تا به حالت اولیه بازگردید. با این کار پیشرفت به 0 بازنشانی می شود.
جعبه گفتگوی پیشرفت
یک کادر گفتگوی پیشرفت می تواند برای نمایش پیشرفت برنامه همانطور که در بخش قبل توضیح داده شد استفاده شود. گفتگوی پیشرفت دارای گزینه های زیر است:
این که آیا پیشرفت مدل را نشان دهد یا خیر. در حالت خاموش، هیچ پیشرفتی از قسمت مدل برنامه به گفتگوی پیشرفت ارسال نمی شود.
نمایش یک یا دو سطح پیشرفت در گفتگوی پیشرفت.
آیا شامل دکمه لغو شود یا خیر. Cancel همچنین برای روش های تعریف شده توسط کاربر کار می کند، زیرا با رسیدن به خط بعدی در متد، اجرا را متوقف می کند.
برای فعال یا غیرفعال کردن این گزینه ها از روش های showProgress استفاده کنید. برای بستن گفتگوی پیشرفت، از روش closeProgress استفاده کنید.
می توانید یک گفتگوی پیشرفت را با یک نوار پیشرفت نامشخص نشان دهید که تا زمانی که گفتگوی پیشرفت را ببندید به چرخش ادامه می دهد. فقط یک گفتگوی پیشرفت را می توان در یک زمان نشان داد. از متدهای showIndeterminateProgress برای نمایش این گفتگوی پیشرفت استفاده کنید.
شیء فرم نوار پیشرفت
شی فرم Progress Bar می تواند اطلاعات کلی پیشرفت برنامه را نشان دهد یا اطلاعات پیشرفت جزئی سفارشی شده را نشان دهد. اگر چک باکس Include model progress را در پنجره تنظیمات گره پنجره اصلی انتخاب کرده باشید ، اطلاعات پیشرفت کلی برنامه در دسترس قرار می گیرد.
هنگامی که Include model progress انتخاب شده است، نوار پیشرفت همان اطلاعات کادر گفتگوی پیشرفت را نشان می دهد. یعنی یک یا دو سطح اطلاعات پیشرفت و یک دکمه لغو بسته به تنظیمات موجود در شی فرم.
وقتی پیشرفت مدل Include پاک شد، نوار پیشرفت را از طریق متدهای setProgressBar کنترل می کنید. اینها نام مسیر شی فرم نوار پیشرفت را می گیرند، برای مثال main/progressbar1 .