JTextField::JTextField(MidpItem *item, JForm *form, QString labelText, int layout, QString text, int maxSize, int constraints, QString initialInputMode) : JItem(item, form) { (void) layout; (void) maxSize; // (void) constraints; (void) initialInputMode; QFormLayout *formLayout = new QFormLayout(this); formLayout->setRowWrapPolicy(QFormLayout::WrapAllRows); tf_label = new QLabel(labelText, this); tf_body = new ExpandableTextEdit(text, this); tf_body->installEventFilter(this); setFocusProxy(tf_body); tf_label->setBuddy(tf_body); tf_label->setTextFormat(Qt::PlainText); tf_label->setWordWrap(true); formLayout->addRow(tf_label, tf_body); if (labelText.isEmpty()) tf_label->hide(); setConstraints(constraints); cont_changed = false; connect(tf_body, SIGNAL(textChanged()), SLOT(contentsModified())); }
Frame::Frame(Widget* parent) : ContainerBase(parent), _margin(0), _drawFrame(true) { setConstraints(MinimumConstraint, MinimumExpandingConstraint); }
DECLARE_EXPORT void SolverMRP::endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement) { if (pAttr.isA(Tags::tag_constraints)) setConstraints(pElement.getInt()); else if (pAttr.isA(Tags::tag_autocommit)) setAutocommit(pElement.getBool()); else if (pAttr.isA(Tags::tag_userexit_flow)) setUserExitFlow(pElement.getString()); else if (pAttr.isA(Tags::tag_userexit_demand)) setUserExitDemand(pElement.getString()); else if (pAttr.isA(Tags::tag_userexit_buffer)) setUserExitBuffer(pElement.getString()); else if (pAttr.isA(Tags::tag_userexit_resource)) setUserExitResource(pElement.getString()); else if (pAttr.isA(Tags::tag_userexit_operation)) setUserExitOperation(pElement.getString()); else if (pAttr.isA(Tags::tag_plantype)) setPlanType(pElement.getInt()); // Less common parameters else if (pAttr.isA(tag_iterationthreshold)) setIterationThreshold(pElement.getDouble()); else if (pAttr.isA(tag_iterationaccuracy)) setIterationAccuracy(pElement.getDouble()); else if (pAttr.isA(tag_lazydelay)) setLazyDelay(pElement.getTimeperiod()); // Default parameters else Solver::endElement(pIn, pAttr, pElement); }
Clock::Clock(Widget* parent) : Widget(parent), _time(NULL), _date(NULL), _timer(NULL) { setConstraints(FixedConstraint, FixedConstraint); _box = new VBoxLayout(); _box->setSpacing(0); _box->setHorizontalAlignment(Alignment::Center); _time = new Label("00:00"); _time->setFont(new Font("decker", 24)); _time->setLayoutAlignment(TextLayout::Center); _date = new Label("Frii181Nov111"); _date->setSingleLine(true); _date->setLayoutAlignment(TextLayout::Center); updateTime(); _box->addWidget(_time); _box->addWidget(_date); addChild(_box); _timer = new Timer(); _timer->sigExec.connect(sigc::mem_fun(this, &Clock::updateTime)); _timer->start(10000); sigGeometryUpdated.connect(sigc::mem_fun(this, &Clock::onClockGeomUpdate)); }
DECLARE_EXPORT int SolverMRP::setattro(const Attribute& attr, const PythonObject& field) { if (attr.isA(Tags::tag_constraints)) setConstraints(field.getInt()); else if (attr.isA(Tags::tag_autocommit)) setAutocommit(field.getBool()); else if (attr.isA(Tags::tag_userexit_flow)) setUserExitFlow(field); else if (attr.isA(Tags::tag_userexit_demand)) setUserExitDemand(field); else if (attr.isA(Tags::tag_userexit_buffer)) setUserExitBuffer(field); else if (attr.isA(Tags::tag_userexit_resource)) setUserExitResource(field); else if (attr.isA(Tags::tag_userexit_operation)) setUserExitOperation(field); else if (attr.isA(Tags::tag_plantype)) setPlanType(field.getInt()); // Less common parameters else if (attr.isA(tag_iterationthreshold)) setIterationThreshold(field.getDouble()); else if (attr.isA(tag_iterationaccuracy)) setIterationAccuracy(field.getDouble()); else if (attr.isA(tag_lazydelay)) setLazyDelay(field.getTimeperiod()); else if (attr.isA(tag_allowsplits)) setAllowSplits(field.getBool()); else if (attr.isA(tag_planSafetyStockFirst)) setPlanSafetyStockFirst(field.getBool()); // Default parameters else return Solver::setattro(attr, field); return 0; }
CheckBox::CheckBox(const std::string& text, Widget* parent) : Button(text, parent) { _layout.setSingleLine(true); setCheckable(true); setConstraints(MinimumConstraint, FixedConstraint); ILOG_TRACE_W(ILX_CHECKBOX); }
void NumericValControl::setDefaultConstraints( bool negativeVisible) { double max = pow(10, m_wholeDigits) - pow(10, -m_fractionalDigits); double min = (negativeVisible) ? -max : 0.0; setConstraints(min, max); }
BarChart::BarChart(unsigned int size, Widget* parent) : Widget(parent), _drawBackground(true), _size(size), _major(20) { ILOG_TRACE_W(ILX_BARCHART); setConstraints(ExpandingConstraint, ExpandingConstraint); }
//generate random thread with a start position and tangent, and total length Thread::Thread(double length, Vector3d& startPos, Vector3d& startTan) { int numPieces = 2; double sampledRadius = DBL_MAX; double randX, randY, randZ; while (sampledRadius >= (length*length)) { randX = 2.0*randomNumUnit()*length - length; randY = 2.0*randomNumUnit()*length - length; randZ = 2.0*randomNumUnit()*length - length; sampledRadius = randX*randX + randY*randY + randZ*randZ; } Vector3d positions[2]; positions[0] = startPos; positions[1](0) = randX+startPos(0); positions[1](1) = randY+startPos(1); positions[1](2) = randZ+startPos(2); //sample tan randomly Vector3d tangents[2]; tangents[0] = startTan; tangents[1](0) = randomNumUnit() - 0.5; tangents[1](1) = randomNumUnit() - 0.5; tangents[1](2) = randomNumUnit() - 0.5; tangents[1].normalize(); //random params for init - needed to seed the energy minimizer double curvature[2] = {randomNumUnit()*RANDOM_THREAD_MAX_CURVATURE_INIT, randomNumUnit()*RANDOM_THREAD_MAX_CURVATURE_INIT}; double torsion[2] = {randomNumUnit()*RANDOM_THREAD_MAX_TORSION_INIT, randomNumUnit()*RANDOM_THREAD_MAX_TORSION_INIT}; double lengths[2] = {length/2.0, length/2.0}; _length = length; //we want to normalize the length of the Thread, so each piece is in "canonical" form threadList = new ThreadPiece(curvature[0], torsion[0], lengths[0]/_length); ThreadPiece* threadCur = threadList; for (int i=1; i < numPieces; i++) { ThreadPiece* threadNext = new ThreadPiece(curvature[i], torsion[i], lengths[i]/_length); threadCur->addSegmentAfter(threadNext); threadCur = threadNext; } setConstraints(positions, tangents); _angle_first_rot = 0.0; opt_params.orig_params_each_piece = NULL; turnOffNoise(); initEnergyParams(); }
SimpleIcon::SimpleIcon(Widget* parent) : Widget(parent), _image(NULL) { setConstraints(ilixi::FixedConstraint, ilixi::FixedConstraint); if (!__iconPack) { __iconPack = new ilixi::IconPack(); __iconPack->parseIcons(DATADIR"/themes/mgui/IconPack.xml"); } }
ossimNumericProperty::ossimNumericProperty(const ossimString& name, const ossimString& value, double minValue, double maxValue) :ossimProperty(name), theValue(value), theType(ossimNumericPropertyType_FLOAT64) { setConstraints(minValue, maxValue); }
ToolButton::ToolButton(const std::string& text, Widget* parent) : Button(text, parent), _icon(NULL), _toolButtonStyle(IconBeforeText), _tbOptions(DrawFrame) { if (__tbThread == NULL) __tbThread = new ToolButtonThread(); ILOG_TRACE_W(ILX_TOOLBUTTON); setConstraints(FixedConstraint, FixedConstraint); _layout.setSingleLine(true); _layout.setAlignment(TextLayout::Center); }
DirectionalButton::DirectionalButton(const std::string& text, Widget* parent) : Button(text, parent), _corners(TopCorners), _buttonType(Arrow), _buttonDirection(Up), _icon(NULL) { ILOG_TRACE_W(ILX_DIRBUTTON); if (__dbThread == NULL) __dbThread = new DirectionalButtonThread(); setConstraints(FixedConstraint, FixedConstraint); _layout.setSingleLine(true); _layout.setAlignment(TextLayout::Center); }
void NumericValControl::initConstraintsFromParam() { // +++++ ASSERT(m_param); printf("NumericValControl::initConstraintsFromParam():\n "); int r; float fFactor; float fOffset; m_param->GetResponse(&r, &fFactor, &fOffset); switch(r) { case BContinuousParameter::B_LINEAR: printf("Linear"); break; case BContinuousParameter::B_POLYNOMIAL: printf("Polynomial"); break; case BContinuousParameter::B_EXPONENTIAL: printf("Exponential"); break; case BContinuousParameter::B_LOGARITHMIC: printf("Logarithmic"); break; default: printf("unknown (?)"); } printf(" response; factor %.2f, offset %.2f\n", fFactor, fOffset); setConstraints( m_param->MinValue(), m_param->MaxValue()); // step not yet supported +++++ 19sep99 // float fStep = m_param->ValueStep(); printf(" min value: %f\n", m_param->MinValue()); printf(" max value: %f\n", m_param->MaxValue()); printf(" value step: %f\n\n", fStep); }
Thread::Thread(double* curvature, double* torsion, double* length, int numPieces, Vector3d* positions, Vector3d* tangents) { if (numPieces < 1) { std::cerr << "requires at least one piece" << std::endl; return; } _length = length[0]; for (int i=1; i < numPieces; i++) { _length += length[i]; } if ( (positions[1] - positions[0]).norm() > _length) { std::cerr << "the length of the thread is less than the distance between positions" << std::endl; exit(0); return; } //we want to normalize the length of the Thread, so each piece is in "canonical" form threadList = new ThreadPiece(curvature[0], torsion[0], length[0]/_length); ThreadPiece* threadCur = threadList; for (int i=1; i < numPieces; i++) { ThreadPiece* threadNext = new ThreadPiece(curvature[i], torsion[i], length[i]/_length); threadCur->addSegmentAfter(threadNext); threadCur = threadNext; } setConstraints(positions, tangents); _angle_first_rot = 0.0; turnOffNoise(); initEnergyParams(); opt_params.orig_params_each_piece = NULL; }
/** * Construct a TextField native peer with label and body. */ TextField::TextField(QWidget *parent, const QString &label, int layout, const QString &text, int maxSize, int constraints, const QString &inputMode) : Item(parent, label, layout) { /* Suppress unused-parameter warning */ (void)inputMode; qedit = new TextFieldBody(this); qedit->setMaxLength(maxSize); setConstraints(constraints); /* The text will be validated by constraints above */ setString(text); setFocusPolicy(QWidget::StrongFocus); /* Delegate focus to MultiLineEdit */ setFocusProxy(qedit); }
AppThumbnail::AppThumbnail(ILXCompositor* compositor, AppInstance* instance, Widget* parent) : AppCompositor(compositor, instance, parent), _close(NULL) { ILOG_TRACE_W(ILX_APPTHUMB); setInputMethod(KeyPointer); setConstraints(FixedConstraint, FixedConstraint); if (!(instance->appInfo()->appFlags() & APP_AUTO_START)) { _close = new ToolButton(""); _close->setToolButtonStyle(ToolButton::IconOnly); _close->setIcon(ILIXI_DATADIR"images/close.png", Size(32, 32)); _close->setDrawFrame(false); _close->setGeometry(164, 0, 32, 32); _close->sigClicked.connect(sigc::bind<AppInstance*>(sigc::mem_fun(_compositor, &ILXCompositor::killApp), _instance)); addChild(_close); } sigGeometryUpdated.connect(sigc::mem_fun(this, &AppThumbnail::updateThumbGeometry)); sigRestacked.connect(sigc::mem_fun(this, &AppThumbnail::handleRestack)); setVisible(false); }
/* * This routine is a bounds-constrained truncated-newton method. * the truncated-newton method is preconditioned by a limited-memory * quasi-newton method (this preconditioning strategy is developed * in this routine) with a further diagonal scaling * (see routine diagonalscaling). */ static tnc_rc tnc_minimize(int n, double x[], double *f, double gfull[], tnc_function *function, void *state, double xscale[], double xoffset[], double *fscale, double low[], double up[], tnc_message messages, int maxCGit, int maxnfeval, int *nfeval, int *niter, double eta, double stepmx, double accuracy, double fmin, double ftol, double xtol, double pgtol, double rescale, tnc_callback *callback) { double fLastReset, difnew, epsmch, epsred, oldgtp, difold, oldf, xnorm, newscale, gnorm, ustpmax, fLastConstraint, spe, yrsr, yksk, *temp = NULL, *sk = NULL, *yk = NULL, *diagb = NULL, *sr = NULL, *yr = NULL, *oldg = NULL, *pk = NULL, *g = NULL; double alpha = 0.0; /* Default unused value */ int i, icycle, oldnfeval, *pivot = NULL, frc; logical lreset, newcon, upd1, remcon; tnc_rc rc = TNC_ENOMEM; /* Default error */ *niter = 0; /* Allocate temporary vectors */ oldg = malloc(sizeof(*oldg)*n); if (oldg == NULL) goto cleanup; g = malloc(sizeof(*g)*n); if (g == NULL) goto cleanup; temp = malloc(sizeof(*temp)*n); if (temp == NULL) goto cleanup; diagb = malloc(sizeof(*diagb)*n); if (diagb == NULL) goto cleanup; pk = malloc(sizeof(*pk)*n); if (pk == NULL) goto cleanup; sk = malloc(sizeof(*sk)*n); if (sk == NULL) goto cleanup; yk = malloc(sizeof(*yk)*n); if (yk == NULL) goto cleanup; sr = malloc(sizeof(*sr)*n); if (sr == NULL) goto cleanup; yr = malloc(sizeof(*yr)*n); if (yr == NULL) goto cleanup; pivot = malloc(sizeof(*pivot)*n); if (pivot == NULL) goto cleanup; /* Initialize variables */ epsmch = mchpr1(); difnew = 0.0; epsred = 0.05; upd1 = TNC_TRUE; icycle = n - 1; newcon = TNC_TRUE; /* Uneeded initialisations */ lreset = TNC_FALSE; yrsr = 0.0; yksk = 0.0; /* Initial scaling */ scalex(n, x, xscale, xoffset); (*f) *= *fscale; /* initial pivot calculation */ setConstraints(n, x, pivot, xscale, xoffset, low, up); dcopy1(n, gfull, g); scaleg(n, g, xscale, *fscale); /* Test the lagrange multipliers to see if they are non-negative. */ for (i = 0; i < n; i++) if (-pivot[i] * g[i] < 0.0) pivot[i] = 0; project(n, g, pivot); /* Set initial values to other parameters */ gnorm = dnrm21(n, g); fLastConstraint = *f; /* Value at last constraint */ fLastReset = *f; /* Value at last reset */ if (messages & TNC_MSG_ITER) fprintf(stderr, " NIT NF F GTG\n"); if (messages & TNC_MSG_ITER) printCurrentIteration(n, *f / *fscale, gfull, *niter, *nfeval, pivot); /* Set the diagonal of the approximate hessian to unity. */ for (i = 0; i < n; i++) diagb[i] = 1.0; /* Start of main iterative loop */ while(TNC_TRUE) { /* Local minimum test */ if (dnrm21(n, g) <= pgtol * (*fscale)) { /* |PG| == 0.0 => local minimum */ dcopy1(n, gfull, g); project(n, g, pivot); if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: |pg| = %g -> local minimum\n", dnrm21(n, g) / (*fscale)); rc = TNC_LOCALMINIMUM; break; } /* Terminate if more than maxnfeval evaluations have been made */ if (*nfeval >= maxnfeval) { rc = TNC_MAXFUN; break; } /* Rescale function if necessary */ newscale = dnrm21(n, g); if ((newscale > epsmch) && (fabs(log10(newscale)) > rescale)) { newscale = 1.0/newscale; *f *= newscale; *fscale *= newscale; gnorm *= newscale; fLastConstraint *= newscale; fLastReset *= newscale; difnew *= newscale; for (i = 0; i < n; i++) g[i] *= newscale; for (i = 0; i < n; i++) diagb[i] = 1.0; upd1 = TNC_TRUE; icycle = n - 1; newcon = TNC_TRUE; if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: fscale = %g\n", *fscale); } dcopy1(n, x, temp); project(n, temp, pivot); xnorm = dnrm21(n, temp); oldnfeval = *nfeval; /* Compute the new search direction */ frc = tnc_direction(pk, diagb, x, g, n, maxCGit, maxnfeval, nfeval, upd1, yksk, yrsr, sk, yk, sr, yr, lreset, function, state, xscale, xoffset, *fscale, pivot, accuracy, gnorm, xnorm, low, up); if (frc == -1) { rc = TNC_ENOMEM; break; } if (frc) { rc = TNC_USERABORT; break; } if (!newcon) { if (!lreset) { /* Compute the accumulated step and its corresponding gradient difference. */ dxpy1(n, sk, sr); dxpy1(n, yk, yr); icycle++; } else { /* Initialize the sum of all the changes */ dcopy1(n, sk, sr); dcopy1(n, yk, yr); fLastReset = *f; icycle = 1; } } dcopy1(n, g, oldg); oldf = *f; oldgtp = ddot1(n, pk, g); /* Maximum unconstrained step length */ ustpmax = stepmx / (dnrm21(n, pk) + epsmch); /* Maximum constrained step length */ spe = stepMax(ustpmax, n, x, pk, pivot, low, up, xscale, xoffset); if (spe > 0.0) { ls_rc lsrc; /* Set the initial step length */ alpha = initialStep(*f, fmin / (*fscale), oldgtp, spe); /* Perform the linear search */ lsrc = linearSearch(n, function, state, low, up, xscale, xoffset, *fscale, pivot, eta, ftol, spe, pk, x, f, &alpha, gfull, maxnfeval, nfeval); if (lsrc == LS_ENOMEM) { rc = TNC_ENOMEM; break; } if (lsrc == LS_USERABORT) { rc = TNC_USERABORT; break; } if (lsrc == LS_FAIL) { rc = TNC_LSFAIL; break; } /* If we went up to the maximum unconstrained step, increase it */ if (alpha >= 0.9 * ustpmax) { stepmx *= 1e2; if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: stepmx = %g\n", stepmx); } /* If we went up to the maximum constrained step, a new constraint was encountered */ if (alpha - spe >= -epsmch * 10.0) { newcon = TNC_TRUE; } else { /* Break if the linear search has failed to find a lower point */ if (lsrc != LS_OK) { if (lsrc == LS_MAXFUN) rc = TNC_MAXFUN; else rc = TNC_LSFAIL; break; } newcon = TNC_FALSE; } } else { /* Maximum constrained step == 0.0 => new constraint */ newcon = TNC_TRUE; } if (newcon) { if(!addConstraint(n, x, pk, pivot, low, up, xscale, xoffset)) { if(*nfeval == oldnfeval) { rc = TNC_NOPROGRESS; break; } } fLastConstraint = *f; } (*niter)++; /* Invoke the callback function */ if (callback) { unscalex(n, x, xscale, xoffset); callback(x, state); scalex(n, x, xscale, xoffset); } /* Set up parameters used in convergence and resetting tests */ difold = difnew; difnew = oldf - *f; /* If this is the first iteration of a new cycle, compute the percentage reduction factor for the resetting test */ if (icycle == 1) { if (difnew > difold * 2.0) epsred += epsred; if (difnew < difold * 0.5) epsred *= 0.5; } dcopy1(n, gfull, g); scaleg(n, g, xscale, *fscale); dcopy1(n, g, temp); project(n, temp, pivot); gnorm = dnrm21(n, temp); /* Reset pivot */ remcon = removeConstraint(oldgtp, gnorm, pgtol * (*fscale), *f, fLastConstraint, g, pivot, n); /* If a constraint is removed */ if (remcon) { /* Recalculate gnorm and reset fLastConstraint */ dcopy1(n, g, temp); project(n, temp, pivot); gnorm = dnrm21(n, temp); fLastConstraint = *f; } if (!remcon && !newcon) { /* No constraint removed & no new constraint : tests for convergence */ if (fabs(difnew) <= ftol * (*fscale)) { if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: |fn-fn-1] = %g -> convergence\n", fabs(difnew) / (*fscale)); rc = TNC_FCONVERGED; break; } if (alpha * dnrm21(n, pk) <= xtol) { if (messages & TNC_MSG_INFO) fprintf(stderr, "tnc: |xn-xn-1] = %g -> convergence\n", alpha * dnrm21(n, pk)); rc = TNC_XCONVERGED; break; } } project(n, g, pivot); if (messages & TNC_MSG_ITER) printCurrentIteration(n, *f / *fscale, gfull, *niter, *nfeval, pivot); /* Compute the change in the iterates and the corresponding change in the gradients */ if (!newcon) { for (i = 0; i < n; i++) { yk[i] = g[i] - oldg[i]; sk[i] = alpha * pk[i]; } /* Set up parameters used in updating the preconditioning strategy */ yksk = ddot1(n, yk, sk); if (icycle == (n - 1) || difnew < epsred * (fLastReset - *f)) lreset = TNC_TRUE; else { yrsr = ddot1(n, yr, sr); if (yrsr <= 0.0) lreset = TNC_TRUE; else lreset = TNC_FALSE; } upd1 = TNC_FALSE; } } if (messages & TNC_MSG_ITER) printCurrentIteration(n, *f / *fscale, gfull, *niter, *nfeval, pivot); /* Unscaling */ unscalex(n, x, xscale, xoffset); coercex(n, x, low, up); (*f) /= *fscale; cleanup: if (oldg) free(oldg); if (g) free(g); if (temp) free(temp); if (diagb) free(diagb); if (pk) free(pk); if (sk) free(sk); if (yk) free(yk); if (sr) free(sr); if (yr) free(yr); if (pivot) free(pivot); return rc; }