double TaskFemConstraintTemperature::get_cflux() const{
    Base::Quantity cflux =  ui->if_temperature->getQuantity();
    double cflux_in_watt = cflux.getValueAs(Base::Quantity::Watt);
    return cflux_in_watt;
}
double TaskFemConstraintTemperature::get_temperature() const{
    Base::Quantity temperature =  ui->if_temperature->getQuantity();
    double temperature_in_kelvin = temperature.getValueAs(Base::Quantity::Kelvin);
    return temperature_in_kelvin;
}
double TaskFemConstraintPressure::getPressure(void) const
{
    Base::Quantity pressure =  ui->if_pressure->getQuantity();
    double pressure_in_MPa = pressure.getValueAs(Base::Quantity::MegaPascal);
    return pressure_in_MPa;
}
예제 #4
0
// constructor method
int ConstraintPy::PyInit(PyObject* args, PyObject* /*kwd*/)
{
    if (PyArg_ParseTuple(args, "")) {
        return 0;
    }

    PyErr_Clear();

    char *ConstraintType;
    int  FirstIndex = Constraint::GeoUndef;
    int  FirstPos   = none;
    int  SecondIndex= Constraint::GeoUndef;
    int  SecondPos  = none;
    int  ThirdIndex = Constraint::GeoUndef;
    int  ThirdPos   = none;
    double Value    = 0;
    int intArg1, intArg2, intArg3, intArg4, intArg5;
    // Note: In Python 2.x PyArg_ParseTuple prints a warning if a float is given but an integer is expected.
    // This means we must use a PyObject and check afterwards if it's a float or integer.
    PyObject* index_or_value;
    PyObject* oNumArg4;
    PyObject* oNumArg5;
    int any_index;

    // ConstraintType, GeoIndex
    if (PyArg_ParseTuple(args, "si", &ConstraintType, &FirstIndex)) {
        if (strcmp("Horizontal",ConstraintType) == 0) {
            this->getConstraintPtr()->Type = Horizontal;
            this->getConstraintPtr()->First = FirstIndex;
            return 0;
        }
        else if (strcmp("Vertical",ConstraintType) == 0) {
            this->getConstraintPtr()->Type = Vertical;
            this->getConstraintPtr()->First = FirstIndex;
            return 0;
        }
    }
    PyErr_Clear();

    if (PyArg_ParseTuple(args, "siO", &ConstraintType, &FirstIndex, &index_or_value)) {
        // ConstraintType, GeoIndex1, GeoIndex2
        if (PyInt_Check(index_or_value)) {
            SecondIndex = PyInt_AsLong(index_or_value);
            bool valid = false;
            if (strcmp("Tangent",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Tangent;
                valid = true;
            }
            else if (strcmp("Parallel",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Parallel;
                valid = true;
            }
            else if (strcmp("Perpendicular",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Perpendicular;
                valid = true;
            }
            else if (strcmp("Equal",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Equal;
                valid = true;
            }
            else if (strstr(ConstraintType,"InternalAlignment") != NULL) {
                this->getConstraintPtr()->Type = InternalAlignment;
                
                valid = true;
                if(strstr(ConstraintType,"EllipseMajorDiameter") != NULL)
                    this->getConstraintPtr()->AlignmentType=EllipseMajorDiameter;
                else if(strstr(ConstraintType,"EllipseMinorDiameter") != NULL)
                    this->getConstraintPtr()->AlignmentType=EllipseMinorDiameter;                    
                else {
                    this->getConstraintPtr()->AlignmentType=Undef;
                    valid = false;
                }
            }
            
            if (valid) {
                this->getConstraintPtr()->First = FirstIndex;
                this->getConstraintPtr()->Second = SecondIndex;
                return 0;
            }
        }
        // ConstraintType, GeoIndex, Value
        if (PyNumber_Check(index_or_value)) { // can be float or int
            Value = PyFloat_AsDouble(index_or_value);
            bool valid = false;
            if (strcmp("Distance",ConstraintType) == 0 ) {
                this->getConstraintPtr()->Type = Distance;
                valid = true;
            }
            else if (strcmp("Angle",ConstraintType) == 0 ) {
                if (PyObject_TypeCheck(index_or_value, &(Base::QuantityPy::Type))) {
                    Base::Quantity q = *(static_cast<Base::QuantityPy*>(index_or_value)->getQuantityPtr());
                    if (q.getUnit() == Base::Unit::Angle)
                        Value = q.getValueAs(Base::Quantity::Radian);
                }
                this->getConstraintPtr()->Type = Angle;
                valid = true;
            }
            else if (strcmp("DistanceX",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = DistanceX;
                valid = true;
            }
            else if (strcmp("DistanceY",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = DistanceY;
                valid = true;
            }
            else if (strcmp("Radius",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Radius;
                // set a value that is out of range of result of atan2
                // this value is handled in ViewProviderSketch
                this->getConstraintPtr()->LabelPosition = 10;
                valid = true;
            }
            if (valid) {
                this->getConstraintPtr()->First    = FirstIndex;
                this->getConstraintPtr()->setValue(Value);
                return 0;
            }
        }
    }
    PyErr_Clear();

    if (PyArg_ParseTuple(args, "siiO", &ConstraintType, &FirstIndex, &any_index, &index_or_value)) {
        // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2
        if (PyInt_Check(index_or_value)) {
            FirstPos = any_index;
            SecondIndex = PyInt_AsLong(index_or_value);
            bool valid = false;
            if (strcmp("Perpendicular", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Perpendicular;
                valid = true;
            }
            else if (strcmp("Tangent", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Tangent;
                valid = true;
            }
            else if (strcmp("PointOnObject", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = PointOnObject;
                valid = true;
            }
            else if (strstr(ConstraintType,"InternalAlignment") != NULL) {
                this->getConstraintPtr()->Type = InternalAlignment;
                
                valid = true;
                   
                if(strstr(ConstraintType,"EllipseFocus1") != NULL)
                    this->getConstraintPtr()->AlignmentType=EllipseFocus1; 
                else if(strstr(ConstraintType,"EllipseFocus2") != NULL)
                    this->getConstraintPtr()->AlignmentType=EllipseFocus2;
                else {
                    this->getConstraintPtr()->AlignmentType=Undef;
                    valid = false;
                }
            }
            if (valid) {
                this->getConstraintPtr()->First    = FirstIndex;
                this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
                this->getConstraintPtr()->Second   = SecondIndex;
                return 0;
            }
        }
        // ConstraintType, GeoIndex1, GeoIndex2, Value
        // ConstraintType, GeoIndex, PosIndex, Value
        if (PyNumber_Check(index_or_value)) { // can be float or int
            SecondIndex = any_index;
            Value = PyFloat_AsDouble(index_or_value);
            //if (strcmp("Distance",ConstraintType) == 0) {
            //    this->getConstraintPtr()->Type   = Distance;
            //    this->getConstraintPtr()->First  = FirstIndex;
            //    this->getConstraintPtr()->Second = SecondIndex;
            //    this->getConstraintPtr()->Value  = Value;
            //    return 0;
            //}
            //else
            if (strcmp("Angle",ConstraintType) == 0) {
                if (PyObject_TypeCheck(index_or_value, &(Base::QuantityPy::Type))) {
                    Base::Quantity q = *(static_cast<Base::QuantityPy*>(index_or_value)->getQuantityPtr());
                    if (q.getUnit() == Base::Unit::Angle)
                        Value = q.getValueAs(Base::Quantity::Radian);
                }
                this->getConstraintPtr()->Type   = Angle;
                this->getConstraintPtr()->First  = FirstIndex;
                this->getConstraintPtr()->Second = SecondIndex;
                this->getConstraintPtr()->setValue(Value);
                return 0;
            }
            else if (strcmp("DistanceX",ConstraintType) == 0) {
                FirstPos = SecondIndex;
                SecondIndex = -1;
                this->getConstraintPtr()->Type = DistanceX;
                this->getConstraintPtr()->First    = FirstIndex;
                this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
                this->getConstraintPtr()->setValue(Value);
                return 0;
            }
            else if (strcmp("DistanceY",ConstraintType) == 0) {
                FirstPos = SecondIndex;
                SecondIndex = -1;
                this->getConstraintPtr()->Type = DistanceY;
                this->getConstraintPtr()->First    = FirstIndex;
                this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) FirstPos;
                this->getConstraintPtr()->setValue(Value);
                return 0;
            }
        }
    }
    PyErr_Clear();

    if (PyArg_ParseTuple(args, "siiiO", &ConstraintType, &intArg1, &intArg2, &intArg3, &oNumArg4)) {
        // Value, ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2
        if (PyInt_Check(oNumArg4)) {
            intArg4 = PyInt_AsLong(oNumArg4);
            bool valid = false;
            if (strcmp("Coincident", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Coincident;
                valid = true;
            }
            else if (strcmp("Horizontal", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Horizontal;
                valid = true;
            }
            else if (strcmp("Vertical", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Vertical;
                valid = true;
            }
            else if (strcmp("Perpendicular", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Perpendicular;
                valid = true;
            }
            else if (strcmp("Tangent", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Tangent;
                valid = true;
            }
            else if (strcmp("TangentViaPoint", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Tangent;
                //valid = true;//non-standard assignment
                this->getConstraintPtr()->First     = intArg1;
                this->getConstraintPtr()->FirstPos  = Sketcher::none;
                this->getConstraintPtr()->Second    = intArg2;
                this->getConstraintPtr()->SecondPos = Sketcher::none;
                this->getConstraintPtr()->Third     = intArg3;
                this->getConstraintPtr()->ThirdPos  = (Sketcher::PointPos) intArg4;
                return 0;
            }
            else if (strcmp("PerpendicularViaPoint", ConstraintType) == 0) {
                this->getConstraintPtr()->Type = Perpendicular;
                //valid = true;//non-standard assignment
                this->getConstraintPtr()->First     = intArg1;
                this->getConstraintPtr()->FirstPos  = Sketcher::none;
                this->getConstraintPtr()->Second    = intArg2;
                this->getConstraintPtr()->SecondPos = Sketcher::none;
                this->getConstraintPtr()->Third     = intArg3;
                this->getConstraintPtr()->ThirdPos  = (Sketcher::PointPos) intArg4;
                return 0;
            }
            if (valid) {
                this->getConstraintPtr()->First     = intArg1;
                this->getConstraintPtr()->FirstPos  = (Sketcher::PointPos) intArg2;
                this->getConstraintPtr()->Second    = intArg3;
                this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) intArg4;
                return 0;
            }
        }
        // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, Value
        if (PyNumber_Check(oNumArg4)) { // can be float or int
            Value = PyFloat_AsDouble(oNumArg4);
            if (strcmp("Distance",ConstraintType) == 0 ) {
                this->getConstraintPtr()->Type = Distance;
                this->getConstraintPtr()->First    = intArg1;
                this->getConstraintPtr()->FirstPos = (Sketcher::PointPos) intArg2;
                this->getConstraintPtr()->Second   = intArg3;
                this->getConstraintPtr()->setValue(Value);
                return 0;
            }
        }
    }
    PyErr_Clear();

    if (PyArg_ParseTuple(args, "siiiiO", &ConstraintType, &intArg1, &intArg2, &intArg3, &intArg4, &oNumArg5)) {
        // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, GeoIndex3
        if (PyInt_Check(oNumArg5)) {
            intArg5 = PyInt_AsLong(oNumArg5);
            if (strcmp("Symmetric",ConstraintType) == 0 ) {
                this->getConstraintPtr()->Type = Symmetric;
                this->getConstraintPtr()->First     = intArg1;
                this->getConstraintPtr()->FirstPos  = (Sketcher::PointPos) intArg2;
                this->getConstraintPtr()->Second    = intArg3;
                this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) intArg4;
                this->getConstraintPtr()->Third     = intArg5;
                return 0;
            }
        }
        // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, Value
        if (PyNumber_Check(oNumArg5)) { // can be float or int
            Value = PyFloat_AsDouble(oNumArg5);
            bool valid=false;
            if (strcmp("Distance",ConstraintType) == 0 ) {
                this->getConstraintPtr()->Type = Distance;
                valid = true;
            }
            else if (strcmp("DistanceX",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = DistanceX;
                valid = true;
            }
            else if (strcmp("DistanceY",ConstraintType) == 0) {
                this->getConstraintPtr()->Type = DistanceY;
                valid = true;
            }
            else if (strcmp("Angle",ConstraintType) == 0 ) {
                if (PyObject_TypeCheck(oNumArg5, &(Base::QuantityPy::Type))) {
                    Base::Quantity q = *(static_cast<Base::QuantityPy*>(oNumArg5)->getQuantityPtr());
                    if (q.getUnit() == Base::Unit::Angle)
                        Value = q.getValueAs(Base::Quantity::Radian);
                }
                this->getConstraintPtr()->Type = Angle;
                valid = true;
            }
            else if (strcmp("AngleViaPoint",ConstraintType) == 0 ) {
                if (PyObject_TypeCheck(oNumArg5, &(Base::QuantityPy::Type))) {
                    Base::Quantity q = *(static_cast<Base::QuantityPy*>(oNumArg5)->getQuantityPtr());
                    if (q.getUnit() == Base::Unit::Angle)
                        Value = q.getValueAs(Base::Quantity::Radian);
                }
                this->getConstraintPtr()->Type = Angle;
                //valid = true;//non-standard assignment
                this->getConstraintPtr()->First     = intArg1;
                this->getConstraintPtr()->FirstPos  = Sketcher::none;
                this->getConstraintPtr()->Second    = intArg2; //let's goof up all the terminology =)
                this->getConstraintPtr()->SecondPos = Sketcher::none;
                this->getConstraintPtr()->Third     = intArg3;
                this->getConstraintPtr()->ThirdPos  = (Sketcher::PointPos) intArg4;
                this->getConstraintPtr()->setValue(Value);
                return 0;
            }
            if (valid) {
                this->getConstraintPtr()->First     = intArg1;
                this->getConstraintPtr()->FirstPos  = (Sketcher::PointPos) intArg2;
                this->getConstraintPtr()->Second    = intArg3;
                this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) intArg4;
                this->getConstraintPtr()->setValue(Value);
                return 0;
            }
        }
    }
    PyErr_Clear();

    if (PyArg_ParseTuple(args, "siiiiiO", &ConstraintType, &FirstIndex, &FirstPos, &SecondIndex, &SecondPos, &ThirdIndex, &index_or_value)) {
        if (PyInt_Check(index_or_value)) {
            ThirdPos = PyInt_AsLong(index_or_value);
            // ConstraintType, GeoIndex1, PosIndex1, GeoIndex2, PosIndex2, GeoIndex3, PosIndex3
            if (strcmp("Symmetric",ConstraintType) == 0 ) {
                this->getConstraintPtr()->Type = Symmetric;
                this->getConstraintPtr()->First     = FirstIndex;
                this->getConstraintPtr()->FirstPos  = (Sketcher::PointPos) FirstPos;
                this->getConstraintPtr()->Second    = SecondIndex;
                this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) SecondPos;
                this->getConstraintPtr()->Third     = ThirdIndex;
                this->getConstraintPtr()->ThirdPos  = (Sketcher::PointPos) ThirdPos;
                return 0;
            }
        }
        if (PyNumber_Check(index_or_value)) { // can be float or int
            Value = PyFloat_AsDouble(index_or_value);
            if (strcmp("SnellsLaw",ConstraintType) == 0 ) {
                this->getConstraintPtr()->Type = SnellsLaw;
                this->getConstraintPtr()->First     = FirstIndex;
                this->getConstraintPtr()->FirstPos  = (Sketcher::PointPos) FirstPos;
                this->getConstraintPtr()->Second    = SecondIndex;
                this->getConstraintPtr()->SecondPos = (Sketcher::PointPos) SecondPos;
                this->getConstraintPtr()->Third     = ThirdIndex;
                this->getConstraintPtr()->ThirdPos  = none;
                this->getConstraintPtr()->setValue(Value);
                return 0;
            }
        }
    }

    std::stringstream str;
    str << "Invalid parameters: ";
    Py::Tuple tuple(args);
    str << tuple.as_string() << std::endl;
    str << "Constraint constructor accepts:" << std::endl
        << "-- empty parameter list" << std::endl
        << "-- Constraint type and index" << std::endl;

    PyErr_SetString(PyExc_TypeError, str.str().c_str());
    return -1;
}
void TaskFemConstraintPressure::onPressureChanged(const Base::Quantity& f)
{
    Fem::ConstraintPressure* pcConstraint = static_cast<Fem::ConstraintPressure*>(ConstraintView->getObject());
    double val = f.getValueAs(Base::Quantity::MegaPascal);
    pcConstraint->Pressure.setValue(val);
}