3 #include <QApplication>
20 int main(
int argc,
char* argv[] )
22 QApplication application( argc, argv );
30 return application.exec();
37 setWindowTitle( tr(
"Create Global Model" ) );
43 QGridLayout* mainLayout =
new QGridLayout(
this );
44 mainLayout->setSpacing ( 2 );
45 mainLayout->setContentsMargins( 2, 2, 2, 2 );
48 QLabel* lb_main =
us_label( tr(
"Combine Models for Global Fit" ) );
61 mainLayout->addWidget( lb_main, row++, 0, 1, 4 );
62 mainLayout->addWidget(
lw_models, row++, 0, 1, 4 );
63 mainLayout->addLayout(
dkdb_cntrls, row++, 0, 1, 4 );
64 mainLayout->addWidget(
pb_prefilt, row, 0, 1, 1 );
65 mainLayout->addWidget(
le_prefilt, row++, 1, 1, 3 );
66 mainLayout->addWidget(
pb_add, row, 0, 1, 2 );
67 mainLayout->addWidget(
pb_reset, row++, 2, 1, 2 );
68 mainLayout->addWidget(
pb_save, row, 0, 1, 2 );
69 mainLayout->addWidget(
pb_help, row, 2, 1, 1 );
70 mainLayout->addWidget(
pb_close, row++, 3, 1, 1 );
74 connect(
pb_add, SIGNAL( clicked() ),
76 connect(
pb_reset, SIGNAL( clicked() ),
77 this, SLOT(
reset() ) );
78 connect(
pb_close, SIGNAL( clicked() ),
79 this, SLOT( close() ) );
80 connect(
pb_help, SIGNAL( clicked() ),
81 this, SLOT(
help() ) );
82 connect(
pb_save, SIGNAL( clicked() ),
83 this, SLOT(
save() ) );
86 tr(
"List of models to combine for a global model" ) );
88 tr(
"Choose RunIDs to pre-filter the models list" ) );
90 tr(
"Chosen RunID pre-filter to the models list" ) );
92 tr(
"Add to the list of component models" ) );
94 tr(
"Clear the models list to allow re-selection" ) );
96 tr(
"Display detailed US_CombineModels documentation text and images" ) );
98 tr(
"Close the US_CombineModels window and exit" ) );
100 tr(
"Create a global model from the listed component models" ) );
108 setMinimumSize( 480, 200 );
116 if ( obj->objectName() ==
"tree-widget" &&
117 e->type() == QEvent::ContextMenu )
126 return US_Widgets::eventFilter( obj, e );
134 QList< US_Model > tmodels;
136 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
138 dialog.move( this->pos() + QPoint( 200, 200 ) );
140 connect( &dialog, SIGNAL(
changed(
bool ) ),
142 QApplication::restoreOverrideCursor();
144 if ( dialog.exec() != QDialog::Accepted )
148 for (
int jj = 0; jj < tmodels.count(); jj++ )
150 QString desc = tmdescs[ jj ];
151 QString sepa = desc.left( 1 );
152 QString mdesc = desc.section( sepa, 1, 1 );
154 this->
models << tmodels[ jj ];
175 const int mxtotrl = 60;
177 int nmodels =
models.size();
178 qDebug() <<
"SAVE: nmodels" << nmodels;
182 QString runID =
mdescs[ 0 ].section(
".", 0, -4 );
186 for (
int ii = 1; ii < nmodels; ii++ )
192 runID =
mdescs[ ii ].section(
".", 0, -4 );
194 if ( !runIDs.contains( runID ) )
197 for (
int jj = 0; jj < kcomps; jj++ )
202 for (
int kk = 0; kk < ncomps; kk++ )
212 if ( dupc )
continue;
215 sc.
name = QString().sprintf(
"SC%04d", ncomps );
219 qDebug() <<
"SAVE: ncomps" << ncomps << cmodel.
components.size();
220 qDebug() <<
"SAVE: nrunIDs" << runIDs.size();
224 QString mdlbnam =
cmodel_name.section(
".", 0, -3 ) +
".";
225 QString mdlanno =
cmodel_name.section(
".", -2, -2 );
226 QString mdlaedt = mdlanno.section(
"_", 0, 0 ) +
"_";
227 QString mdlaanl =
"a" + QDateTime::currentDateTime().toString(
"yyMMddhhmm" ) +
"_";
228 QString mdlatyp = mdlanno.section(
"_", 2, 2 ).section(
"-", 0, 0 ) +
"-GL";
229 QString mdliter =
"_local_i01.model";
230 cmodel_name = mdlbnam + mdlaedt + mdlaanl + mdlatyp + mdliter;
240 QString odesc =
cmodel_name.section(
".", -3, -1 );
243 QString msg1 = tr(
"An output combined model has been created. "
244 "It's description is:<br/><b>" )
246 + tr(
"It combines %1 models with a total of %2 components. "
248 .arg( nmodels ).arg( ncomps )
249 + tr(
" <b>OK</b> to output the model as is;<br/>"
250 " <b>Edit</b> to modify the model description (runID);<br/>"
251 " <b>Cancel</b> to abort model creation.<br/>" );
253 mbox.setWindowTitle( tr(
"Save Global Model" ) );
254 mbox.setText ( msg1 );
255 QPushButton *pb_ok = mbox.addButton( tr(
"OK" ),
256 QMessageBox::YesRole );
257 QPushButton *pb_edit = mbox.addButton( tr(
"Edit" ) ,
258 QMessageBox::AcceptRole );
259 QPushButton *pb_canc = mbox.addButton( tr(
"Cancel" ),
260 QMessageBox::RejectRole );
261 mbox.setEscapeButton ( pb_canc );
262 mbox.setDefaultButton( pb_ok );
266 if ( mbox.clickedButton() == pb_canc )
return;
268 if ( mbox.clickedButton() == pb_edit )
275 int curriln = runID.length();
276 QString msg2 = tr(
"The default run ID for the output combined"
277 " model is <br/><b>" ) + runID +
"</b>.<br/><br/>"
278 + tr(
"You may modify this part of the model description"
279 " (currently %1 characters).<br/>"
280 "Use alphanumeric characters, underscores, or hyphens"
282 "Enter so the total is from 3 to %2 characters.<br/><br/>"
283 "It is <b>strongly</b> recommended that you only"
284 " <b>append</b> any descriptive string to the original<br/>"
285 "runID in order to facilitate finding the model in"
286 " subsequent model loader dialogs." )
287 .arg( curriln ).arg( mxtotrl );
288 runID = QInputDialog::getText(
this,
289 tr(
"Modify Global Model Description RunID" ),
290 msg2, QLineEdit::Normal, runID, &ok );
294 runID.remove( QRegExp(
"[^\\w\\d_-]" ) );
295 int slen = runID.length();
299 runID += QString(
"GLO" ).left( 3 - slen );
301 else if ( slen > mxtotrl )
303 runID = runID.left( mxtotrl );
320 qDebug() <<
"SAVE: DB";
329 cmodel.
write( fnamo );
330 qDebug() <<
"SAVE: fnamo" << fnamo;
352 srdiag.move( this->pos() + QPoint( 200, 200 ) );
353 connect( &srdiag, SIGNAL( dkdb_changed (
bool ) ),
356 if ( srdiag.exec() == QDialog::Accepted )
362 pfmsg = tr(
"(none chosen)" );
364 else if ( nruns == 1 )
365 pfmsg = tr(
"RunID prefilter - 1 run: " )
366 + QString(
pfilts[ 0 ] ).left( 20 ) +
"...";
369 pfmsg = tr(
"RunID prefilter - %1 runs: " ).arg( nruns )
370 + QString(
pfilts[ 0 ] ).left( 20 ) +
"*,...";