示例#1
0
int OCCFace::revolve(OCCBase *shape, OCCStruct3d p1, OCCStruct3d p2, double angle)
{
    try {
        const TopoDS_Shape& shp = shape->getShape();
        // Only accept Edge or Wire
        TopAbs_ShapeEnum type = shp.ShapeType();
        if (type != TopAbs_EDGE && type != TopAbs_WIRE) {
            StdFail_NotDone::Raise("Expected Edge or Wire");
        }
        
        gp_Dir direction(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
        gp_Ax1 axisOfRevolution(gp_Pnt(p1.x, p1.y, p1.z), direction);
        
        BRepPrimAPI_MakeRevol MR(shp, axisOfRevolution, angle, Standard_False);
        if (!MR.IsDone()) {
            StdFail_NotDone::Raise("Failed in revolve operation");;
        }
        this->setShape(MR.Shape());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to revolve");
        }
        return 0;
    }
    return 1;
}
示例#2
0
文件: QtSkin.cpp 项目: BigEd/wp34s
bool QtSkin::convertAttributesToColor(const QString& aName, const QXmlAttributes& theAttributes, QColor& aColor)
{
	int redIndex=theAttributes.index("red");
	int greenIndex=theAttributes.index("green");
	int blueIndex=theAttributes.index("blue");

	if(redIndex<0 || greenIndex<0 || blueIndex<0)
	{
		setErrorMessage("Invalid attributes for color "+aName);
		return false;
	}
	else
	{
		int red, green, blue;
		if(!convertStringToInteger(theAttributes.value(redIndex), red))
		{
			setErrorMessage("Invalid red: "+theAttributes.value(redIndex)+" for "+aName);
			return false;
		}
		if(!convertStringToInteger(theAttributes.value(greenIndex), green))
		{
			setErrorMessage("Invalid green: "+theAttributes.value(greenIndex)+" for "+aName);
			return false;
		}
		if(!convertStringToInteger(theAttributes.value(blueIndex), blue))
		{
			setErrorMessage("Invalid blue: "+theAttributes.value(blueIndex)+" for "+aName);
			return false;
		}
		aColor.setRgb(red, green, blue);
	}

	return true;
}
示例#3
0
bool ComicModel::open(const QString &fileUrl)
{
    if (m_currentFilename != "") {
        close();
    }
    QUrl url(fileUrl);
    std::shared_ptr<QuaZip> zip(new QuaZip(url.toLocalFile()));
    zip->setFileNameCodec("Shift-JIS");
    bool result = zip->open(QuaZip::mdUnzip);
    if (result) {
        int pageCount;
        if (parseZip("", zip, pageCount)) {
            setErrorMessage();
            addRecentFile(url.toLocalFile());
            m_currentFilename = url.toLocalFile();
            emit currentFilenameChanged(m_currentFilename);
            emit maxPageChanged(m_list.size());
            QSettings settings;
            QString key = QString(RECENTPAGE_KEY).arg(m_currentFilename);
            int page = settings.value(key, 1).toInt();
            setCurrentPage(page);
        } else {
            setErrorMessage("zip file is empty.");
        }
    } else {
        setErrorMessage("open file error.");
    }
    return result;
}
示例#4
0
  void programFlashTask(void* p){
    int sector = flashSectorToWrite;
    uint32_t size = flashSizeToWrite;
    uint8_t* source = (uint8_t*)flashAddressToWrite;
    if(sector >= 0 && sector < MAX_USER_PATCHES && size <= 128*1024){
      uint32_t addr = getFlashAddress(sector);
      eeprom_unlock();
      int ret = eeprom_erase(addr);
      if(ret == 0)
	ret = eeprom_write_block(addr, source, size);
      eeprom_lock();
      registry.init();
      if(ret == 0){
	// load and run program
	int pc = registry.getNumberOfPatches()-MAX_USER_PATCHES+sector;
	program.loadProgram(pc);
	// program.loadDynamicProgram(source, size);
	program.resetProgram(false);
      }else{
	setErrorMessage(PROGRAM_ERROR, "Failed to write program to flash");
      }
    }else if(sector == 0xff && size < MAX_SYSEX_FIRMWARE_SIZE){
      flashFirmware(source, size);
    }else{
      setErrorMessage(PROGRAM_ERROR, "Invalid flash program command");
    }
    vTaskDelete(NULL);
  }
示例#5
0
QImage ComicModel::loadImage(int arg)
{
    QImage img;
    --arg;
    //qDebug() << m_list[arg]->fileName;
    if (m_list[arg]->zip->setCurrentFile(m_list[arg]->fileName)) {
        QuaZipFile file(m_list[arg]->zip.get());
        if (file.open(QIODevice::ReadOnly)) {
            QByteArray data = file.readAll();
            file.close();
            if (img.loadFromData(data)) {
                //qDebug() << "load success" << data.size();
                setErrorMessage();
            } else {
                //qDebug() << "loadFromData error.";
                setErrorMessage("error: loadFromData()");
            }
        } else {
            //qDebug() << "file open error.";
            setErrorMessage("error: file.open()");
        }
    } else {
        //qDebug() << "setCurrentFile failed." << m_zip->getZipError();
        setErrorMessage("error: setCurrentFile()");
    }
    return img;
}
示例#6
0
int OCCTools::writeSTEP(const char *filename, std::vector<OCCBase *> shapes)
{
    try {
        STEPControl_Writer writer;
        IFSelect_ReturnStatus status;
        
        Interface_Static::SetCVal("xstep.cascade.unit","M");
        Interface_Static::SetIVal("read.step.nonmanifold", 1);
        
        for (unsigned i = 0; i < shapes.size(); i++) {
            status = writer.Transfer(shapes[i]->getShape(), STEPControl_AsIs);
            if (status != IFSelect_RetDone) {
                StdFail_NotDone::Raise("Failed to write STEP file");
            }
        }
        status = writer.Write(filename);
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        //printf("ERROR: %s\n", e->GetMessageString());
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to write STEP file");
        }
        return 0;
    }
    return 1;
}
void CharacteristicsEditor::readCharacteristicValue()
{
    if ((m_characteristicProperties & GATT_CHARACTERISTIC_PROP_READ) == 0) {
        setErrorMessage("GATT descriptors: Read not permitted");
        return;
    }

    uint8_t *characteristicBuffer = (uint8_t *)alloca(m_characteristicMTU);
    if (!characteristicBuffer) {
        setErrorMessage("GATT characteristic: Not enough memory");
        bt_gatt_disconnect_instance(m_gattInstance);
        return;
    }

    QString descriptorString;

    int byteCount = 0;
    uint8_t more = 1;
    for (int offset = 0; more; offset += byteCount) {
        byteCount = bt_gatt_read_value(m_gattInstance, m_characteristicValueHandle.toUShort(), offset, characteristicBuffer, m_characteristicMTU, &more);
        if (byteCount < 0) {
            setErrorMessage(QString("Unable to read characteristic value: %1 (%2)").arg(errno).arg(strerror(errno)));
            break;
        }

        descriptorString += bufferToString(characteristicBuffer, byteCount);
    }

    setCharacteristicValue(descriptorString);
    setCharacteristicValueText(descriptorString);
}
示例#8
0
int OCCFace::createConstrained(std::vector<OCCEdge *> edges, std::vector<OCCStruct3d> points) {
    try {
        BRepOffsetAPI_MakeFilling aGenerator;
        for (unsigned i = 0; i < edges.size(); i++) {
            OCCEdge *edge = edges[i];
            aGenerator.Add(edge->edge, GeomAbs_C0);
        }
        for (unsigned i = 0; i < points.size(); i++) {
            gp_Pnt aPnt(points[i].x, points[i].y, points[i].z);
            aGenerator.Add(aPnt);
        }
        aGenerator.Build();
        this->setShape(aGenerator.Shape());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create face");
        }
        return 0;
    }
    return 1;
}
示例#9
0
int OCCFace::extrude(OCCBase *shape, OCCStruct3d p1, OCCStruct3d p2) {
    try {
        const TopoDS_Shape& shp = shape->getShape();
        // Only accept Edge or Wire
        TopAbs_ShapeEnum type = shp.ShapeType();
        if (type != TopAbs_EDGE && type != TopAbs_WIRE) {
            StdFail_NotDone::Raise("expected Edge or Wire");
        }
        
        gp_Vec direction(gp_Pnt(p1.x, p1.y, p1.z),
                         gp_Pnt(p2.x, p2.y, p2.z));
        gp_Ax1 axisOfRevolution(gp_Pnt(p1.x, p1.y, p1.z), direction);
        
        BRepPrimAPI_MakePrism MP(shp, direction, Standard_False);
        this->setShape(MP.Shape());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to extrude");
        }
        return 0;
    }
    return 1;
}
示例#10
0
int OCCEdge::createArc(OCCVertex *start, OCCVertex *end, OCCStruct3d center) {
    try {
        gp_Pnt aP1(start->X(), start->Y(), start->Z());
        gp_Pnt aP2(center.x, center.y, center.z);
        gp_Pnt aP3(end->X(), end->Y(), end->Z());
        
        Standard_Real Radius = aP1.Distance(aP2);
        gce_MakeCirc MC(aP2,gce_MakePln(aP1, aP2, aP3).Value(), Radius);
        const gp_Circ& Circ = MC.Value();
        
        Standard_Real Alpha1 = ElCLib::Parameter(Circ, aP1);
        Standard_Real Alpha2 = ElCLib::Parameter(Circ, aP3);
        Handle(Geom_Circle) C = new Geom_Circle(Circ);
        Handle(Geom_TrimmedCurve) arc = new Geom_TrimmedCurve(C, Alpha1, Alpha2, false);
        
        this->setShape(BRepBuilderAPI_MakeEdge(arc, start->vertex, end->vertex));
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create arc");
        }
        return 0;
    }
    return 1;
}
void CharacteristicsEditor::writeCharacteristicValue(bool withResponse)
{
    if ((withResponse && (m_characteristicProperties & GATT_CHARACTERISTIC_PROP_WRITE) == 0) ||
        (!withResponse && (m_characteristicProperties & GATT_CHARACTERISTIC_PROP_WRITE_NORESP) == 0)) {
        setErrorMessage("GATT descriptors: Write not permitted");
        return;
    }

    const int characteristicLen = m_characteristicValue.size();
    uint8_t *characteristicBuffer = (uint8_t *)alloca(characteristicLen / 2 + 1);
    if (!characteristicBuffer) {
        setErrorMessage("GATT characteristic: Not enough memory");
        bt_gatt_disconnect_instance(m_gattInstance);
        return;
    }

    const int consumed = stringToBuffer(m_characteristicValue, characteristicBuffer, characteristicLen);

    if (consumed > 0) {
        int byteCount;
        if (withResponse) {
            byteCount = bt_gatt_write_value(m_gattInstance, m_characteristicValueHandle.toUShort(), 0, characteristicBuffer, (consumed / 2));
        } else {
            byteCount = bt_gatt_write_value_noresp(m_gattInstance, m_characteristicValueHandle.toUShort(), 0, characteristicBuffer, (consumed / 2));
        }

        if (byteCount < 0) {
            setErrorMessage(QString("Unable to write characteristic value: %1 (%2)").arg(errno).arg(strerror(errno)));
        }
    }
}
示例#12
0
int OCCFace::offset(double offset, double tolerance = 1e-6) {
    try {
        BRepOffset_MakeOffset MO(this->getShape(), offset, tolerance, BRepOffset_Skin,
                                 Standard_False, Standard_False, GeomAbs_Intersection, Standard_False);
        
        if (!MO.IsDone()) {
            StdFail_NotDone::Raise("Failed to offset face");
        }
        
        const TopoDS_Shape& tmp = MO.Shape();
        BRepCheck_Analyzer aChecker(tmp);
        
        if (tmp.IsNull() || !aChecker.IsValid()) {
            StdFail_NotDone::Raise("offset result not valid");
        }
        
        this->setShape(tmp);
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to offset face");
        }
        return 0;
    }
    return 1;
}
示例#13
0
int OCCFace::createPolygonal(std::vector<OCCStruct3d> points)
{
    try {
        BRepBuilderAPI_MakePolygon MP;
        for (unsigned i=0; i<points.size(); i++) {
            MP.Add(gp_Pnt(points[i].x, points[i].y, points[i].z));
        }
        MP.Close();
        if (!MP.IsDone()) {
            StdFail_NotDone::Raise("failed to create face");;
        }
        BRepBuilderAPI_MakeFace MF(MP.Wire(), false);
        this->setShape(MF.Face());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create face");
        }
        return 0;
    }
    return 1;
}
示例#14
0
int OCCTools::writeVRML(const char *filename, std::vector<OCCBase *> shapes)
{
    try {
        BRep_Builder B;
        TopoDS_Compound shape;
        B.MakeCompound(shape);
        
        for (unsigned i = 0; i < shapes.size(); i++) {
            B.Add(shape, shapes[i]->getShape());
        }
        VrmlAPI_Writer writer;
        writer.Write(shape, filename);
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        //printf("ERROR: %s\n", e->GetMessageString());
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to write VRML file");
        }
        return 0;
    }
    return 1;
}
void CharacteristicsEditor::writeCharacteristicDescriptor(int row, const QString &value)
{
    if (row < 0 || row >= m_descriptorsModel->size())
        return;

    QVariantMap currentMap = m_descriptorsModel->value(row).toMap();

    const int descriptorLen = value.size();

    uint8_t *descriptorBuffer = (uint8_t *)alloca( value.size() / 2 + 1 );
    if (!descriptorBuffer) {
        setErrorMessage("GATT descriptor: Not enough memory");
        bt_gatt_disconnect_instance(m_gattInstance);
        return;
    }

    const int consumed = stringToBuffer(value, descriptorBuffer, descriptorLen);

    if (consumed > 0) {
        const int byteCount = bt_gatt_write_value(m_gattInstance, currentMap["handle"].toInt(), 0, descriptorBuffer, (consumed / 2) );
        if (byteCount < 0) {
            setErrorMessage(QString("Unable to write descriptor value: %1 (%2)").arg(errno).arg(strerror(errno)));
        } else {
            currentMap["value"] = value;

            m_descriptorsModel->replace(row, currentMap);
        }
    }
}
示例#16
0
bool AutoUpdate::softWareBackup()
{
    if(sNewPath.isEmpty())
    {
        setErrorMessage(tr("新程序路径获取失败"));
        return false;
    }
    bool ret=QFile::exists(sOldPath);
    if(!ret)
    {
        setErrorMessage(tr("查找收费软件失败"));
        return ret;
    }
    ret=QFile::exists(sOldPath+"_bak");
    if(ret)
    {
        QFile::remove(sOldPath+"_bak");
    }
    ret=QFile::rename(sOldPath,sOldPath+"_bak");
    if(!ret)
    {
        setErrorMessage(tr("现有程序备份失败"));
    }
    return ret;
}
示例#17
0
VarType TypeCheckerVisitor::getOperationResultType(TokenKind tokenKind, AstNode* left, AstNode* right) {
	VarType result = VT_INVALID;
	VarType leftType = getNodeType(left);
	VarType rightType = getNodeType(right);
	switch (tokenKind) {
	case tOR: case tAND: case tEQ: case tNEQ:
	case tGT: case tGE: case tLT: case tLE:
		result = VT_INT;
		break;
	case tADD:
		if (leftType == VT_STRING || rightType == VT_STRING) {
			result = VT_STRING;
		} else if (leftType == VT_DOUBLE || rightType == VT_DOUBLE) {
			result = VT_DOUBLE;
		} else if (leftType == VT_INT && rightType == VT_INT) {
			result = VT_INT;
		}
		break;
	case tSUB: case tMUL: case tDIV: case tMOD:
		if (leftType == VT_DOUBLE || rightType == VT_DOUBLE) {
			result = VT_DOUBLE;
		} else if (leftType == VT_INT && rightType == VT_INT) {
			result = VT_INT;
		}
		break;
	case tASSIGN:
		if (!(isAssignable(leftType, rightType))) {
			setErrorMessage(right, "bad type");
		}
		result = leftType;
		break;
	case tDECRSET:
		if (!(isAssignable(leftType, rightType)) || (leftType == VT_STRING)) {
			setErrorMessage(right, "bad type");
		}
		result = leftType;
		break;
	case tINCRSET:
		if (leftType == VT_STRING) {
			result = VT_STRING;
		} else if (leftType == VT_DOUBLE) {
			result = VT_DOUBLE;
		} else if (leftType == VT_INT && rightType == VT_INT) {
			result = VT_INT;
		}
		break;
	default:
		assert(0);
	}
	if (leftType == VT_VOID) {
		setErrorMessage(left, "Should not be of type void");
	}
	if (rightType == VT_VOID) {
		setErrorMessage(right, "Should not be of type void");
	}
	return result;
}
示例#18
0
bool Pumping::initializeSettings(std::shared_ptr<geometry::Geometry> geometry)
{
    if (geometry->hasOption("pumping_ts"))
    {
        this->pumpingTs = geometry->getOrCreateTimeseries(geometry->getOption("pumping_ts"));
    }
    else
    {
        if (geometry->hasOption("pumping_rate"))
        {
            if (!tryParse(geometry->getOption("pumping_rate"), this->pumpingRate))
            {
                setErrorMessage("Unable to parse pumping_rate option");
                return false;
            }
        }
        else
        {
            return false;
        }
        
        if (geometry->hasOption("days_before_pumping"))
        {
            if (!tryParse(geometry->getOption("days_before_pumping"), this->daysBeforePumping))
            {
                setErrorMessage("Unable to parse days_before_pumping option");
                return false;
            }
        }
        else
        {
            return false;
        }

        if (geometry->hasOption("pumping_threshold"))
        {
            if (!tryParse(geometry->getOption("pumping_threshold"), this->pumpingThreshold))
            {
                setErrorMessage("Unable to parse pumping_threshold option");
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    
    // Start out the event-to-pumping interval counter with the correct duration to allow for
    // pumping from the start of a simulation.
    this->secondsSinceLastInflow = SECS_PER_DAY * this->daysBeforePumping;

    return true;
}
示例#19
0
int OCCEdge::createSpline(OCCVertex *start, OCCVertex *end, std::vector<OCCStruct3d> points,
                           double tolerance)
{
    try {
        Standard_Boolean periodic = false;
        Standard_Real tol = tolerance;
        
        int vertices = 0;
        if (start != NULL && end != NULL) {
            vertices = 2;
        }
        
        int nbControlPoints = points.size();
        Handle(TColgp_HArray1OfPnt) ctrlPoints;
        ctrlPoints = new TColgp_HArray1OfPnt(1, nbControlPoints + vertices);
        
        int index = 1;
        
        if (vertices) {
            ctrlPoints->SetValue(index++, gp_Pnt(start->X(), start->Y(), start->Z()));  
        }
        
        for (int i = 0; i < nbControlPoints; i++) {
            gp_Pnt aP(points[i].x,points[i].y,points[i].z);
            ctrlPoints->SetValue(index++, aP);
        }
        
        if (vertices) {
            ctrlPoints->SetValue(index++, gp_Pnt(end->X(), end->Y(), end->Z()));
        }
        
        GeomAPI_Interpolate INT(ctrlPoints, periodic, tol);
        INT.Perform();
        
        Handle(Geom_BSplineCurve) curve = INT.Curve();
        if (vertices) {
            this->setShape(BRepBuilderAPI_MakeEdge(curve, start->vertex, end->vertex));
        } else {
            this->setShape(BRepBuilderAPI_MakeEdge(curve));
        }
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create spline");
        }
        return 0;
    }
    return 1;
}
示例#20
0
// =========================================================
void pamParser::Read(const std::string &pamfile, seqAlign* pSeqAlign)
{
    setError(0);
    std::ifstream ipam;
    ipam.open(pamfile.c_str());

    int end   = pamfile.length();
    int slash = pamfile.find_last_of("/");
    std::string file_name = pamfile.substr(slash+1,(end-slash-5));

    if (!ipam) {
      std::string errorMessage = " Error, Can't Find " + pamfile;
      setErrorMessage(errorMessage);
      errorLogger.throwError( "seqAlign::Read", errorMessage, 1);
    }

    if (pSeqAlign) {
      pSeqAlign->setPAMFile(pamfile);
    }
    else {
      std::string errorMessage = " Error ";
      setErrorMessage(errorMessage);
      errorLogger.throwError( "seqAlign::Read", errorMessage, 1);
    }

    std::vector<std::string> characters;
    int i = -1;
    std::string fileline = "";
    while (ipam) {
      getline(ipam,fileline);
      if (fileline.substr(0,1) == "#") {
        continue;
      }
      if (i == -1) { // first line
        splitString(fileline, " ", characters, 0);
        pSeqAlign->setPAMSize(static_cast<int>(characters.size()));
        for (unsigned int i = 0; i < characters.size(); i++) {
          pSeqAlign->setPAMType(i, characters[i]);
        }
      }
      else {
        std::vector<std::string> words;
        splitString(fileline, " ", words, 0);
        for (unsigned int j = 1; j < words.size(); j++) {
          double v = string2Double(words[j]);
          pSeqAlign->setPAMValue(i, j-1, v);
        }
      }
      i++;
    }
    ipam.close();
}
示例#21
0
bool AutoUpdate::haveUpdateFile()
{
    if(sNewPath.isEmpty())
    {
        setErrorMessage(tr("新程序路径获取失败"));
        return false;
    }
    if(!QFile::exists(sNewPath))
    {
        qDebug()<<sNewPath;
        setErrorMessage(tr("没有要更新的程序"));
        return false;
    }
    return true;
}
示例#22
0
int OCCEdge::createBezier(OCCVertex *start, OCCVertex *end, std::vector<OCCStruct3d> points)
{
    try {
        int nbControlPoints = points.size();
        int vertices = 0;
        if (start != NULL && end != NULL) {
            vertices = 2;
        }
        
        TColgp_Array1OfPnt ctrlPoints(1, nbControlPoints + vertices);
        
        int index = 1;
        if (vertices) {
            ctrlPoints.SetValue(index++, gp_Pnt(start->X(), start->Y(), start->Z()));
        }
        
        for (int i = 0; i < nbControlPoints; i++) {
            gp_Pnt aP(points[i].x,points[i].y,points[i].z);
            ctrlPoints.SetValue(index++, aP);
        }
        
        if (vertices)
            ctrlPoints.SetValue(index++, gp_Pnt(end->X(), end->Y(), end->Z())); 
        
        Handle(Geom_BezierCurve) bezier = new Geom_BezierCurve(ctrlPoints);
        
        if (vertices) {
            this->setShape(BRepBuilderAPI_MakeEdge(bezier, start->vertex, end->vertex));
        } else {
            this->setShape(BRepBuilderAPI_MakeEdge(bezier));
        }
        
        if (this->length() <= Precision::Confusion()) {
            StdFail_NotDone::Raise("bezier not valid");
        }
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create bezier");
        }
        return 0;
    }
    return 1;
}
void AddMetaItemPage::onDelayedMergeRequest()
{
	QString metaId = FMetaTabWindow->metaRoster()->itemMetaContact(FAddWidget->contactJid());
	FMergeRequestId = !metaId.isEmpty() ? FMetaTabWindow->metaRoster()->mergeContacts(FMetaTabWindow->metaId(), QList<QString>() << metaId) : QString::null;
	if (FMergeRequestId.isEmpty())
		setErrorMessage(Qt::escape(tr("Failed to merge contacts.")));
}
示例#24
0
Devices::Devices()
{
    char error[PCAP_ERRBUF_SIZE];
    if(pcap_findalldevs(&alldevs,error)==-1) {
        setErrorMessage("Error in finding devices: " + QString(error),QMessageBox::Critical);
    }
}
示例#25
0
/**
* @param curEnv java environment where the exception occurred.
*/
JniCallMethodException::JniCallMethodException(JNIEnv * curEnv) throw() : JniException(curEnv)
{
    std::string errorMessage = "Exception when calling Java method : ";
    errorMessage += getJavaDescription() + "\n" + getJavaStackTrace();
    errorMessage += what();
    setErrorMessage(errorMessage);
}
示例#26
0
    SimpleHttpResult* SimpleHttpClient::getResult () {
      switch (_state) {
        case IN_WRITE:
          _result->setResultType(SimpleHttpResult::WRITE_ERROR);
          break;

        case IN_READ_HEADER:
        case IN_READ_BODY:
        case IN_READ_CHUNKED_HEADER:
        case IN_READ_CHUNKED_BODY:
          _result->setResultType(SimpleHttpResult::READ_ERROR);
          break;

        case FINISHED:
          _result->setResultType(SimpleHttpResult::COMPLETE);
          break;

        case IN_CONNECT:
        default: {
          _result->setResultType(SimpleHttpResult::COULD_NOT_CONNECT);
          if (!haveErrorMessage()) {
            setErrorMessage("Could not connect");
          }
          break;
        }
      }

      if (haveErrorMessage() && (_result->getHttpReturnMessage().length() == 0)) {
        _result->setHttpReturnMessage(_errorMessage);
      }

      return _result;
    }
示例#27
0
void PlanOperation::operator()() noexcept {
  if (allDependenciesSuccessful()) {
    try {
      LOG4CXX_DEBUG(logger, "Executing " << vname() << "(" << _operatorId << ")");
      execute();
      return;
    }
    catch (const std::exception& ex) {
      setErrorMessage(ex.what());
    }
    catch (...) {
      setErrorMessage("Unknown error");
    }
  }
  setState(OpFail);
}
示例#28
0
void KPrinter::preparePrinting()
{
	// check if already prepared (-> do nothing)
	if (d->m_ready) return;

	// re-initialize error
	setErrorMessage(QString::null);

	// re-initialize margins and page size (by default, use Qt mechanism)
	setRealPageSize(NULL);

	// print-system-specific setup, only if not printing to file
	if (option("kde-isspecial") != "1")
		d->m_impl->preparePrinting(this);

	// set the correct resolution, if needed (or reset it)
	int res = option( "kde-resolution" ).toInt();
	if ( d->m_useprinterres && res > 0 )
		d->m_wrapper->setResolution( res );
	else
		d->m_wrapper->setResolution( d->m_defaultres );

	// standard Qt settings
	translateQtOptions();

	d->m_ready = true;
dumpOptions(d->m_options);
}
void AddMetaItemPage::onMetaActionResult(const QString &AActionId, const QString &AErrCond, const QString &AErrMessage)
{
	Q_UNUSED(AErrMessage);
	if (AActionId == FCreateRequestId)
	{
		if (!AErrCond.isEmpty())
			setErrorMessage(Qt::escape(tr("Failed to create new contact.")));
	}
	else if (AActionId == FMergeRequestId)
	{
		if (!AErrCond.isEmpty())
			setErrorMessage(Qt::escape(tr("Failed to merge contacts.")));
		else if (FRosterChanger)
			FRosterChanger->subscribeContact(FMetaTabWindow->metaRoster()->streamJid(),FAddWidget->contactJid());
	}
}
示例#30
0
int OCCWire::createWire(std::vector<OCCEdge *> edges)
{
    try {
        BRepBuilderAPI_MakeWire MW;
        for (unsigned i=0; i<edges.size(); i++) {
            OCCEdge *edge = edges[i];
            MW.Add(edge->getEdge());
        }
        
        BRepBuilderAPI_WireError error = MW.Error();
        switch (error)
        {
            case BRepBuilderAPI_EmptyWire:
            {
                StdFail_NotDone::Raise("Wire empty");
                break;
            }
            case BRepBuilderAPI_DisconnectedWire:
            {
                StdFail_NotDone::Raise("Disconnected wire");
                break;
            }
            case BRepBuilderAPI_NonManifoldWire :
            {
                StdFail_NotDone::Raise("non-manifold wire");
                break;
            }
        }
        
        this->setShape(MW.Wire());
        
        // possible fix shape
        if (!this->fixShape())
            StdFail_NotDone::Raise("Shapes not valid");
        
    } catch(Standard_Failure &err) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        const Standard_CString msg = e->GetMessageString();
        if (msg != NULL && strlen(msg) > 1) {
            setErrorMessage(msg);
        } else {
            setErrorMessage("Failed to create wire");
        }
        return 0;
    }
    return 1;
}