Ejemplo n.º 1
0
void DlgExtrusion::fetchDir()
{
    bool lengths_are_at_defaults =
        (fabs(ui->spinLenFwd->value().getValue() - 10.0) < 1e-7)
        && (fabs(ui->spinLenRev->value().getValue() - 0.0) < 1e-7);
    bool lengths_are_zero =
        (fabs(ui->spinLenFwd->value().getValue() - 0.0) < 1e-7)
        && (fabs(ui->spinLenRev->value().getValue() - 0.0) < 1e-7);

    try {
        Base::Vector3d pos, dir;
        bool fetched = false;
        bool dir_has_valid_magnitude = false;
        if(this->getDirMode() == Part::Extrusion::dmEdge) {
            App::PropertyLinkSub lnk;
            this->getAxisLink(lnk);
            fetched = Part::Extrusion::fetchAxisLink(lnk, pos, dir);
            dir_has_valid_magnitude = fetched;
        } else if (this->getDirMode() == Part::Extrusion::dmNormal) {
            App::PropertyLink lnk;
            lnk.setValue(&this->getShapeToExtrude());
            dir = Part::Extrusion::calculateShapeNormal(lnk);
            fetched = true;
        }
        if (dir_has_valid_magnitude && lengths_are_at_defaults) {
            ui->spinLenFwd->setValue(0);
        } else if (!dir_has_valid_magnitude && lengths_are_zero) {
            ui->spinLenFwd->setValue(1.0);
        }
        if (fetched) {
            this->setDir(dir);
        }
    } catch (Base::Exception &) {

    } catch (...) {

    }
}
Ejemplo n.º 2
0
bool DlgExtrusion::validate()
{
    //check source shapes
    if (ui->treeWidget->selectedItems().isEmpty()) {
        QMessageBox::critical(this, windowTitle(),
            tr("No shapes selected for extrusion. Select some, first."));
        return false;
    }

    //check axis link
    QString errmsg;
    bool hasValidAxisLink = false;
    try{
        App::PropertyLinkSub lnk;
        this->getAxisLink(lnk);
        Base::Vector3d dir, base;
        hasValidAxisLink = Part::Extrusion::fetchAxisLink(lnk, base, dir);
    } catch(Base::Exception &err) {
        errmsg = QString::fromUtf8(err.what());
    } catch(Standard_Failure &err) {
        errmsg = QString::fromLocal8Bit(err.GetMessageString());
    } catch(...) {
        errmsg = QString::fromUtf8("Unknown error");
    }
    if (this->getDirMode() == Part::Extrusion::dmEdge && !hasValidAxisLink){
        if (errmsg.length() > 0)
            QMessageBox::critical(this, windowTitle(), tr("Extrusion direction link is invalid.\n\n%1").arg(errmsg));
        else
            QMessageBox::critical(this, windowTitle(), tr("Direction mode is to use an edge, but no edge is linked."));
        ui->txtLink->setFocus();
        return false;
    } else if (this->getDirMode() != Part::Extrusion::dmEdge && !hasValidAxisLink){
        //axis link is invalid, but it is not required by the mode. We shouldn't complain it's invalid then...
        ui->txtLink->clear();
    }

    //check normal
    if (this->getDirMode() == Part::Extrusion::dmNormal){
        errmsg.clear();
        try {
            App::PropertyLink lnk;
            lnk.setValue(&this->getShapeToExtrude()); //simplified - check only for the first shape.
            Part::Extrusion::calculateShapeNormal(lnk);
        } catch(Base::Exception &err) {
            errmsg = QString::fromUtf8(err.what());
        } catch(Standard_Failure &err) {
            errmsg = QString::fromLocal8Bit(err.GetMessageString());
        } catch(...) {
            errmsg = QString::fromUtf8("Unknown error");
        }
        if (errmsg.length() > 0){
            QMessageBox::critical(this, windowTitle(), tr("Can't determine normal vector of shape to be extruded. Please use other mode. \n\n(%1)").arg(errmsg));
            ui->rbDirModeNormal->setFocus();
            return false;
        }
    }

    //check axis dir
    if (this->getDirMode() == Part::Extrusion::dmCustom){
        if(this->getDir().Length() < Precision::Confusion()){
            QMessageBox::critical(this, windowTitle(),
                tr("Extrusion direction is zero-length. It must be non-zero."));
            ui->dirX->setFocus();
            return false;
        }
    }

    //check lengths
    if (!ui->chkSymmetric->isChecked()
            && fabs(ui->spinLenFwd->value().getValue() + ui->spinLenRev->value().getValue()) < Precision::Confusion()
            && ! (fabs(ui->spinLenFwd->value().getValue() - ui->spinLenRev->value().getValue()) < Precision::Confusion())){
        QMessageBox::critical(this, windowTitle(),
            tr("Total extrusion length is zero (length1 == -length2). It must be nonzero."));
        ui->spinLenFwd->setFocus();
        return false;
    }

    return true;
}